Can the set method of map in ES6 determine whether a key exists or not and then treat it differently?

requirement is how to determine that the key already exists and then deal with it differently when adding a key value to the map?

let msg = new Map()
msg.set("a",{count: 10})
msg.set("a",{count: 20})

 a count,a,

how should this be achieved?

Es6
Dec.30,2021

opening the console and swinging the keyboard is a new Map ()
clipboard.png
MDN:

clipboard.png

?:

let msg = new Map()
msg.set('a',{count: 10})
if(msg.has('a')){
    let data=msg.get('a')
    data.count+=10
    msg.set('a',data)
}else{
        msg.set('a',{count:10})

}

borrow the method upstairs,

let msg = new Map()
msg.set('a',{count: 10});
if(msg.has('a')) {
    var val = msg.get('a').count;
    val += val;
    msg.set('a',{count: val} )
}else {
    mgs.set('a', {count: 10})
}
Menu