Possible Duplicate:
Split array into chunks
I am trying to convert an array of values into a new array of paired values.
For example i need to convert:
var arr = [1,2,3,4,5,6,7,8];
into:
arr = [[1,2], [3,4], [5,6], [7,8]];
I tried using jQuery's .map() method like so but this did not work for me:
arr= $.map(arr, function(n, i){
return [n + ',' + n[ i + 1 ]];
});
mapwhen given an array as a return flattens it into the new array, you probably just want to do it yourself.[...].mapis a built-in function in javascript (ECMAScript 5th edition, supported by all modern browsers, unless you count the people who still haven't clicked the "upgrade to IE9" button that Microsoft shoves infront of you).