re: Protip: JSON ignores 'undefined' VIEW POST


Since the value either exists or is undefined,

donkey.fur_pos.map(i => i[3] ? i[3] : undefined)

can be simplified to:

donkey.fur_pos.map(i => i[3])

It's inaccurate though to say that the undefined will be removed - in what way are you using it for which this is the case?

What you can do however is eg:

    .map(i => i[3])

which will remove all falsey statements including undefined and null, but also 0 and false, so you may want a more robust filter function, depending on your objective.


+1 .filter(Boolean) is very elegant solution 😎

code of conduct - report abuse