I have this Map
let map = new Map(Object.entries({
a: 1,
b: {
c: 2,
method() {console.log('test')}
}
}
));
Now, I want to change map.b.method. How can I achieve that?
It's just an object stored inside the map. Get a reference to it and modify it as you'd like.
let map = new Map(Object.entries({
a: 1,
b: {
c: 2,
method() {
console.log('test')
}
}
}));
map.set('b', {
...map.get('b'),
method: function() {
console.log('It works ;)');
}
});
map.get('b').method();
map.get('b').method = ...?map.set('b', { ...map.get('b'), method() { … } })Mapis, and I'm being really broad here, basically just anObjectthat allows you to use things other thanStringsas keys. How would you do this with a regularObject? Start there and tell us what issues you run into.