Answers for "get unique strings in array javascript"

7

unique values in array javascript

let uniqueItems = [...new Set(items)]
Posted by: Guest on September-06-2020
1

javascript get unique elements in array

function toUniqueArray(a){
    var newArr = [];
    for (var i = 0; i < a.length; i++) {
        if (newArr.indexOf(a[i]) === -1) {
            newArr.push(a[i]);
        }
    }
  return newArr;
}
var colors = ["red","red","green","green","green"];
var colorsUnique=toUniqueArray(colors); // ["red","green"]
Posted by: Guest on July-23-2019

Code answers related to "get unique strings in array javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language