I have an array of elements where the entries are sparse. How can I easily condense the sparse array into a dense array so that I don\'t have to keep checking for null and
In vanilla JS, works on all browsers:
function filt(a) { var b = []; for(var i = 0;i < a.length;i++) { if (a[i] !== undefined && a[i] !== null) { b.push(a[i]); } } return b; } > filt([1,undefined,3]) [1, 3]