【发布时间】:2021-05-01 18:41:50
【问题描述】:
我有一个数组,我想检查数组中的任何元素是否重复。
["item1", "item2", "item3"] //false All the items are unique
["item1", "item2", "item1"] //true There are 2 of the same items.
【问题讨论】:
-
任何项目?还是一个特定的(如“item1”)?
-
将数组转换为
Set。如果集合和数组的元素个数相同,则它们都是唯一的。 -
一个特定的,比如“item1”
-
小心“相同”和“重复”
-
所以
["item1", "item2", "item2"]是假的?
标签: javascript node.js