Supposed I have 2 dimensional array in javascript and I want remove the empty element something like this [] in array, for example:
// like this
var newArray = [["test1", "test2"], ["test3", "test4"], []];
// or like this
var newArray= [["test1", "test2"], [], ["test3", "test4"]];
and my code so far
var newArray= [["test1", "test2"], ["test3", "test4"], []];
for(var loop = 0; loop < newArray.length; loop++){
if (newArray[loop] === null){
// remove this empty element
newArray[loop].slice();
}
}
console.log(newArray);
And my output so far
[ [ 'test1', 'test2' ], [ 'test3', 'test4' ], [] ]
How to remove that empty element? and when I print to the console the result that I want must:
[ [ 'test1', 'test2' ], [ 'test3', 'test4' ] ]
Please help and thank you
twoDArray = twoDArray.filter( array => array.length)