javascript - Array filter with possible undefined properties -




i have array of objects may or not contain property.

so, in order filter it, this:

array = array.filter(v => v.myproperty != undefined); array = array.filter(v => v.myproperty[0] != undefined); 

this removes ones myproperty undefined and, afterwards, ones first element inside myproperty.

is there way of having single liner prevents me applying filter array twice?

something like:

array = array.filter((v => v.myproperty || [])[0] != undefined); 

what about:

filtered_array = array.filter(element => element.property && element.property[0]); 

what condition evaluate left part first. if it's true, try evaluate right part , return result.

fiddle here.





wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -