Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Filtering array so it would remove all undefined objects

I need to filter an array so it would remove undefined objects from it.

enter image description here

I tried with lodash _.filter but didn't succeed (returned completely empty array)

_.filter(myArray, _.isEmpty)

I'm using Angular 6 so anything with typescript or lodash would be perfect.

like image 898
raouaoul Avatar asked Nov 19 '25 02:11

raouaoul


1 Answers

An easier way:

_.filter(myArray, Boolean)

This rids the array of nulls, 0's and undefined's.

like image 108
rrd Avatar answered Nov 20 '25 17:11

rrd



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!