Reputation: 7734
I'm deleting some array object in traditional way: delete subDirectories[index]
. So, just after that this object is changing to [empty]
one. Now, how to filter that, undefined, bool, NaN
nothing works. I'm working with Vue.js and this contains an vuex
action. Can anybody help?
Upvotes: 0
Views: 7112
Reputation: 1944
If you want to delete all null, undefined, (or any false-like) values in an array, you can just do:
var arr = [1,3,5, null, False];
var res = arr.filter(val=>val);
console.log(res); // [1,3,5]
Alternatively, you can explicitly remove null and undefined:
var res = arr.filter(val => (val!==undefined) && (val!==null));
console.log(res); // [1,3,5]
Upvotes: 6