How do I remove empty elements from an array in JavaScript?
Is there a straightforward way, or do I need to loop through it and remove them manually?
Just ES6 and newer versions method, assume array is below:
ES6
const arr = [1,2,3,undefined,4,5,6,undefined,7,8,undefined,undefined,0,9];
Simple way:
const clearArray = arr.filter( i => i );