You can use js reduce
initialArray.reduce(function(result, value, index, array) {
if (index % 2 === 0)
result.push(array.slice(index, index + 2));
return result;
}, []);
More Related Contents:
- Convert JSON to array in Javascript
- Does an array contain a specific item? [duplicate]
- Cartesian product of multiple arrays in JavaScript
- Counting the occurrences / frequency of array elements
- How to get the difference between two arrays of objects in JavaScript
- JavaScript “new Array(n)” and “Array.prototype.map” weirdness
- How to delete an item from state array?
- How to find if an array contains a specific string in JavaScript/jQuery?
- Check if every element in one array is in a second array
- How to get objects value if its name contains dots?
- How to find the array index with a value?
- JavaScript runtime complexity of Array functions
- Merge Two Arrays so that the Values Alternate
- For loop through Array only shows last value
- appending array to FormData and send via AJAX
- Angular2 component’s “this” is undefined when executing callback function
- How can I only keep items of an array that match a certain condition?
- JavaScript flattening an array of arrays of objects
- Best way to convert string to array of object in javascript?
- Why is ‘for(var item in list)’ with arrays considered bad practice in JavaScript?
- To find Index of Multidimensional Array in Javascript
- Filter array of objects whose any properties contains a value
- Two arrays, where items in array x can be in array y but not vice versa, test all permutations
- How to loop through array in jQuery?
- Is array both associative and indexed?
- How to find the indexes of all occurrences of an element in array?
- Find all values by specific key in a deep nested object
- How can I get a character array from a string?
- Add key value pair to all objects in array
- javaScript: Can a comma occur after the last set of values in an array?