Answers for "get unique items javascript"

49

javascript array unique values

var arr = [55, 44, 65,1,2,3,3,34,5];
var unique = [...new Set(arr)]

//just  var unique = new Set(arr) wont be an array
Posted by: Guest on July-03-2020
0

how to find unique values in an array in js using function

// app.js

Array.prototype.unique = function() {
  let arr = [];
  for(let i = 0; i < this.length; i++) {
      if(!arr.includes(this[i])) {
          arr.push(this[i]);
      }
  }
  return arr; 
}

const ages = [26, 27, 26, 26, 28, 28, 29, 29, 30]
const uniqueAges = ages.unique()
console.log(uniqueAges)
Posted by: Guest on May-03-2022

Code answers related to "get unique items javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language