admin管理员组文章数量:1336340
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]
本文标签: javascriptFilter empty array objectStack Overflow
版权声明:本文标题:javascript - Filter [empty] array object - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742391032a2465995.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论