可能是重复问题:
查找JavaScript数组中重复值的最简单方法
如何检查一个数组是否有重复值?
如果数组中有相同元素,则返回true。否则,返回false。
['hello','goodbye','hey'] //return false because no duplicates exist
['hello','goodbye','hello'] // return true because duplicates exist
请注意,我不关心查找重复项,只想知道数组是否包含重复项的布尔结果。
var test=['hello','goodbye','hello'] ; if ( test.length != _.unique(test).length ) { // some code }
- Sai Ram