How to filter out an array in such a way that the empty indexes should trigger a new array and the result becomes a two dimensional array. Tried with Vanilla JavaScript and it works, looking for a solution using modern array methods.
var list = ["1", "2", "3", "", "4", "5", "6", "", "7", "8", "9", ""];
Vanilla JavaScript eg:-
var tmp_list = [];
for(let i=0; i<list.length; i++) {
if(list[i].length > 0) {
tmp_list.push(list[i]);
} else {
result_array.push(tmp_list);
tmp_list = [];
}
}
for eg:-
Array indexes with values should be consolidated into an array which is then pushed to the result array
Expected result
var result_array = [["1", "2", "3"], ["4", "5", "6"], ["7", "8", "9"]];