【发布时间】:2015-11-12 15:41:15
【问题描述】:
使用 ES6 集合,我可以这样做:
let ints = new Set([1,2,3])
console.log(ints.has(3))
它打印true,因为3 是 在集合中。
但是数组呢?例如
let coordinates = new Set([[1,1], [1,2], [2,0]])
console.log(coordinates.has([1,2]))
这打印出false。
As you can see in this CodePen demo
那么,如果不首先将坐标转换为字符串(例如 ['1,1', '1,2', '2,0']),我如何才能像数组是可散列的一样处理数组中的数组?
【问题讨论】:
-
两个不同的对象永远不会相互
===。 -
此外,它不允许自定义相等标准:stackoverflow.com/questions/29759480/…
标签: javascript arrays ecmascript-6