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?
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?
- check this stackoverflow./questions/281264/… – Gaurang Dave Commented Feb 6, 2018 at 0:47
- I don't understand what you are saying. Are you sure this is javascript? – keithlee96 Commented Feb 6, 2018 at 0:48
- @keithlee96 I've added the console log screen. – Lukas Commented Feb 6, 2018 at 0:49
- @GaurangDave tried this, and just like above, none of them doesn't work :( – Lukas Commented Feb 6, 2018 at 0:49
- @Lukas Can you share the JS code (operation you are performing)? – Gaurang Dave Commented Feb 6, 2018 at 1:10
1 Answer
Reset to default 6If 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]
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742391033a4435019.html
评论列表(0条)