I have an array with 100 elements, I want to take an element from 10th to 15th (10, 11, 12, 13, 14, 15), than from 20th to 25th, than from 30th to 35th, from 40th to 45th and from 50th to 55th, so I always have a gap= 4 and store to a new 2D value. I found out how to store to 2D array, but how could I make this gap?
this is how I could make a chunk of size 6 (because I always need first six element of "decade")
var newArr = [];
while(arr.length) newArr.push(arr.splice(0,6));
or
function splitArray(array, part) {
var tmp = [];
for(var i = 0; i < array.length; i += part) {
tmp.push(array.slice(i, i + part));
}
return tmp;
}
console.log(splitArray(m1, 6));
But first of all I have to make a new array of elements (10-15, 20-25 and so on...). How could I do this?