简体   繁体   中英

Filter [empty] array object

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?

在此处输入图片说明

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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM