JavaScript - Map() increment value

前端 未结 5 1459
说谎
说谎 2021-01-07 18:53

I have a map as follows:

let map = new Map();
map.set(\"a\", 1);
//Map is now {\'a\' => 1}

I want to change the value of a

5条回答
  •  不知归路
    2021-01-07 19:36

    Map#get returns the value of the specified element. It is opposite of an object accessor (object['a']) and is not eligible for a left-hand side assignment.

    The conclusion is to use always Map#set for setting a new value.

提交回复
热议问题