問題:
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