0

I have an array say

arr1 = [[1,2,3,4],[5,6,7,8],[9,10,11,12]]

I want to slice it and pick 2nd and 3rd column.

I have tried using slice but it did not work.

var result = arr1.slice(1,3);

but I dont get the desired output which should be

[[2,3],[6,7],[10,11]]

Is it because I am using Google spreadsheet to collect data?

TheMaster
  • 45,448
  • 6
  • 62
  • 85
Mask
  • 573
  • 7
  • 24

1 Answers1

4

You need to map the sliced arrays.

const
    array = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]],
    customSlice = array => array.slice(1, 3),
    result = array.map(customSlice);
    
console.log(result);
.as-console-wrapper { max-height: 100% !important; top: 0; }
Nina Scholz
  • 376,160
  • 25
  • 347
  • 392