There is an array of 400 elements, I want to sort them so that the elements in the array were by 4. for example [[1,2,3,4], [a,b,c,d], [true,false,true,false]] and so on ..
tried to implement it like this:
var arr = [....]// не сортированный массив. var main = []; var secondary = []; for(i=0; i<arr.length; i++){ secondary.push(arr[i]); if(secondary.length === 4){ main.push(secondary); secondary.length = 0; // очищаю чтобы наполнить по новой } } But when cleaning the secondary array, it is also cleared in the main .. (after all, if you just push the elements, and after clearing the variable, then the main element is not deleted, unlike the array)