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();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.