【发布时间】:2020-04-10 17:49:35
【问题描述】:
我确信这应该很容易解决,但我想不通。 我有一个 Map 对象,其中包含一组字符串作为键,初始值设置为零。
let n = new Map();
n.set("example1", 0);
n.set("example2", 0);
n.set("example3", 0);
const conditions = () =>{
let exampStr;
//random set of conditions
return exampStr; // can return example1, example2 o example3
}
// use the result of the function conditions() to add 1 to the value of the map n at the given key.
如果满足一组条件,我有一个函数应该 ++ 某个键的值。我不知道如何通过传递对应的键来更改此映射的给定键的值。
【问题讨论】:
-
用
n.get()取值,加1,用n.set()保存?你问的是这个吗?