Transposing a 2D-array in JavaScript

I’ve got an array of arrays, something like: [ [1,2,3], [1,2,3], [1,2,3], ] I would like to transpose it to get the following array: [ [1,1,1], [2,2,2], [3,3,3], ] It’s not difficult to programmatically do so using loops: function transposeArray(array, arrayLength){ var newArray = []; for(var i = 0; i < array.length; i++){ newArray.push([]); }; … Read more

Javascript equivalent of Python’s zip function

Is there a javascript equivalent of Python’s zip function? That is, given multiple arrays of equal lengths create an array of pairs. For instance, if I have three arrays that look like this: var array1 = [1, 2, 3]; var array2 = [‘a’,’b’,’c’]; var array3 = [4, 5, 6]; The output array should be: var … Read more