Answers for "javascript array get values with unique property value"

3

javascript get unique values from key

const unique = [...new Set(array.map(item => item.age))];
Posted by: Guest on June-05-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 "javascript array get values with unique property value"

Code answers related to "Javascript"

Browse Popular Code Answers by Language