问题:
This question already has answers here :
这个问题已经在这里有了答案 :
Get all unique values in a JavaScript array (remove duplicates) (79 answers)
获取JavaScript数组中的所有唯一值(删除重复项) (79个答案)
Closed last year .
去年关闭。
I have a very simple JavaScript array that may or may not contain duplicates. 我有一个非常简单的JavaScript数组,其中可能包含重复项,也可能不包含重复项。
var names = ["Mike","Matt","Nancy","Adam","Jenny","Nancy","Carl"];
I need to remove the duplicates and put the unique values in a new array. 我需要删除重复项,并将唯一值放入新数组中。
I could point to all the codes that I've tried but I think it's useless because they don't work. 我可以指出我尝试过的所有代码,但是我认为这没用,因为它们不起作用。 I accept jQuery solutions too. 我也接受jQuery解决方案。
Similar question: 类似的问题:
- Get all non-unique values (ie: duplicate/more than one occurrence) in an array 获取数组中的所有非唯一值(即:重复/多次出现)
解决方案:
参考一: https://stackoom.com/question/cj3F/从JS数组中删除重复的值-duplicate参考二: https://oldbug.net/q/cj3F/Remove-duplicate-values-from-JS-array-duplicate
来源:oschina
链接:https://my.oschina.net/u/4428122/blog/4308974