javascript - Filter [empty] array object - Stack Overflow

I'm deleting some array object in traditional way: delete subDirectories[index]. So, just after th

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?

Share Improve this question asked Feb 6, 2018 at 0:45 LukasLukas 7,74420 gold badges79 silver badges127 bronze badges 5
  • 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
Add a ment  | 

1 Answer 1

Reset to default 6

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]

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742391033a4435019.html

相关推荐

  • javascript - Filter [empty] array object - Stack Overflow

    I'm deleting some array object in traditional way: delete subDirectories[index]. So, just after th

    5小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信