I have an array of objects like such...
const myObjects: MyObjects[] = [{id: 1, data: "blah"}, {id: 2, data: "foo"}, {id: 3, data: "bar"}];
I want to set this data into a Map based on id.
The way I have now is a forEach loop, but is there a simpler way or a method I am missing on the Map type ? I find myself doing this over and over again and thinking must be a simpler way.
i.e
const myMap = new Map<number, MyObject>();
myObjects.forEach(obj => {
myMap.set(obj.id, obj);
});
I want to move them to a Map so they are easier to access by id versus iterating over the whole array.