javascript get unique items of array

Solutions on MaxInterview for javascript get unique items of array by the best coders in the world

showing results for - "javascript get unique items of array"
Finn
16 Mar 2016
1function toUniqueArray(a){
2    var newArr = [];
3    for (var i = 0; i < a.length; i++) {
4        if (newArr.indexOf(a[i]) === -1) {
5            newArr.push(a[i]);
6        }
7    }
8  return newArr;
9}
10var colors = ["red","red","green","green","green"];
11var colorsUnique=toUniqueArray(colors); // ["red","green"]
queries leading to this page
nodejs array remove duplicatedhow to remove duplicates from two array in javascriptmake array unique javascriptjavascript array uniqueduplicate array values javascriptremove duplicates from an arrayremove duplicates from an array in jsmultidimensional array remove duplicates javascriptjavascript new unique arrayremove duplicates in array javascriptremove dulplicates array jsremove duplicates from array javascriptremove duplicate elements from array javascripthow to remove duplicate values in javascript arrayjavascript array map without duplicatesstore only unique values in array javascripthow to get the unique values from an array in javascriptjs remove duplicates from arrayts remove duplicates from arrayremove duplicates from array javascript using for loophow to set only unique values in array in javascriptfilter duplicates javascriptfunction removeduplicates js how to fetch only unique values from array in jsjs array uniquehow to find unique array of of object in javascriptget unique strings from array javascriptnodejs remove duplicates from arrayremove duplicate from js arrayunique array jsremove duplicates from arrayarray unique elements nodejavascript find unique values in arrayunique array javascripttypescript get all unique values from arrayjavascript get unique elements in arrayavoid duplication in array javascriptarray filter duplicatesunique id from array jsjavascript array remove duplicatesremove duplicate array element javascriptcreate unique array javascriptremove repeat value in array javascriptremove repited elements in array javascriptremove repeated elements in array javascriptremove the duplicate elements in array in javascriptdelete repeated sub elements in array javascriptremove duplicates from an array jsstrip array of duplicatesremove duplicate item from arrayfind the unique element in an arrayes6 unique arraytypescript javascript list without duplicatesjavascript remove duplicates from arrayjs filter arrays doublesjavascript array extract unique valuesjavascript get unique items of array