I am working with an object of the ObjectOfArrays type:
type ObjectOfArrays = {
[id: string]: Array<string>
};
Throughout my code, I need to add strings to the correct array based on the id. Currently, I am using the following approach:
if (id in obj)
obj[id].push("text");
else
obj[id] = ["text"];
Is there a more concise way to achieve this? While I understand it may not be as straightforward as dealing with numeric objects, as discussed here, I am interested in exploring alternative methods for notation.
I would appreciate any suggestions or references. Thank you.