I JavaScript, has a spread-like operator for optional elements been considered? Something like:

['a', ?'b']
=> ['a', 'b']

['a', ?null]
=> ['a']

I know you can emulate this with a spread + conditional + array literal, but I think this could be way simpler to understand.

@rauschma or any other JavaScript experts

@acjay It feels a little too niche to me, but you can ask for feedback here: es.discourse.group

Note that TC39 tends to be very conservative w.r.t. adding things to the language (I know because I had suggestions too in the past 😀).

Spreading as a work-around can become more elegant if “add no elements” is represented by an empty Array.

Follow

@rauschma Sorry for the delayed response, but thanks, Axel!

Sign in to participate in the conversation
CleverLibre Social

CleverLibre Social is an inclusive social instance for open discussion, learning, and community.
All cultures welcome.
Hate speech and harassment strictly forbidden.