I have a JS Map that looks like this let mappy = new Map<string, string[]>()
I would like to add items to the array using the key and I could do this:
mappy.set(theKey, mappy.get(theKey).push('somevalue'));
that just seems like overkill to me. if I used a simple object I could easily just do
let mappy = {};
mappy[theKey] = [];
..and then later mappy[theKey].push('somevalue') but this kinda negates the typed object idea of TS
Is there any way i could add to that array in the map without first "getting" it?
.set()anything? You just need to.get()the array and.push()to it. In fact.push()returns a number - the new length of the array. So if you.set(someKey, someArray.push())you're setting the value ofsomeKeyto a number.