【发布时间】:2018-02-21 03:25:37
【问题描述】:
有了数组,我可以使用array[index]++
但是有了Map,我只知道map.set(index,map.get(index)+1)
我认为它看起来很糟糕,如果index是一个长名称函数,我必须将它分成两行。
有没有更简洁的方式来实现map[index]++
【问题讨论】:
-
Is there a more concise way否(不包括明显的 -Map.prototype.incr = function(x) { this.set(x, this.get(x) + 1); }) -
我认为真正的问题是......为什么你需要像数组一样使用 Map 对象......?
-
例如统计每一项的数量
标签: javascript dictionary ecmascript-6 es6-map