问题:
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. 我须要删除重复项,并将惟一值放入新数组中。 less
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解决方案。 url
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