I have an object of the following type:
type ObjectOfArrays = {
[id: string]: Array<string>
};
At multiple places in my code I want to push strings to the correct array, referenced by the id
.
Currently, I would have to do this in the following way:
if (id in obj)
obj[id].push("text");
else
obj[id] = ["text"];
Is it possible to do this in a shorter way? I understand it probably won't be as simple as an object with numbers, like done here. However, I am curious if there are alternative notations.
Any suggestions or references are welcome, thanks.