Let's say you have a hash o of arrays; for example registered callbacks for events, when each event can have 0 or more callbacks.
Is there a better way to say this in ES6?
if (key in o) o[key].push(x); else o[key] = [x]
By "better" I mean more easily understood by other developers. Possibly more concise, but not at the expense of readability. A particular (common) problem is that o is often a longer expression, e.g. this.listeners, and repeating it three times seems suboptimal. So real code might look like this:
if (event in this.listeners)
this.listeners[event].push(callback);
else
this.listeners[event] = [callback];