I have an array outer_array
. I try to push some array inside the outer_array
. But some of the pushed array are empty. I don't want those empty array. I can remove it manually, but i need to delete it from the loop. here is my code:
var ary = [1, 2, 3, 4, 5, 6];
var splitLength = 3;
var outer_lis = [];
var first_limit = 0;
var second_limit = splitLength;
for (var i=0; i<ary.length; i++) {
outer_lis.push(ary.slice(first_limit, second_limit));
first_limit += splitLength;
second_limit += splitLength;
}
console.log(outer_lis);
// Result
[ [ 1, 2, 3 ], [ 4, 5, 6 ], [], [], [], [] ]
I searched for a solution but i got results in php
. I dont understand php
. If you can give me a solution for this problem its much appreciated. because i am a beginner in Javascript.