The zip
function in Underscore.js is used to create an array of tuples by grouping elements of each array together by their index. Here is an example of how to use the zip
function:
index.tsx148 chars5 lines
In the example above, we have two arrays, array1
and array2
. When we call _.zip(array1, array2)
, we create a new array containing arrays of elements from array1
and array2
at each corresponding index.
If the arrays passed to _.zip()
are of different lengths, the resulting array will be the same length as the shortest array. Any missing values will be represented by undefined
.
index.tsx149 chars5 lines
That's how you can use the zip
function from the Underscore library in JavaScript.
gistlibby LogSnag