var arr = []; console.log(arr); console.log("Length: " + arr.length); arr[1] = [{},{}]; console.log(arr); console.log("Length: " + arr.length); arr[3] = [{},{}]; console.log(arr); console.log("Length: " + arr.length);
So when I create an array like above it gives empty/undefined elements in between.
I want to remove those empty/undefined elements while preserving the index values.
vm.eArray = vm.eArray.filter(function (arr) { return arr.length; });
I'm using the above code to remove the undefined elements but it messes my index/key values.
Or is there any way to avoid it at first place?
Map
.