sets in javascript code example
Example 1: set js
const numbers = [2,3,4,4,2,3,3,4,4,5,5,6,6,7,5,32,3,4,5]
console.log([...new Set(numbers)])
Example 2: set in javascript
let mySet = new Set()
mySet.add(1)
mySet.add(5)
mySet.add(5)
mySet.add('some text')
let o = {a: 1, b: 2}
mySet.add(o)
mySet.add({a: 1, b: 2})
mySet.has(1)
mySet.has(3)
mySet.has(5)
mySet.has(Math.sqrt(25))
mySet.has('Some Text'.toLowerCase())
mySet.has(o)
mySet.size
mySet.delete(5)
mySet.has(5)
mySet.size
console.log(mySet)
Example 3: set in javascript
const firstSet = new Set([1, 2, 3]);
firstSet.add('hi');
firstSet.add(3);
firstSet.delete('hi');
console.log(firstSet.has('hi'));
console.log(firstSet);
for (const entry of firstSet.values()) {
console.log(entry);
Example 4: js new array from new set
return Array.from(new Set(this.posts.map(e => e.category)))
Example 5: object set js
let nombres = [10, 45, 75, 10 ,24,45 ] ;
let monSet = new Set() ;
monSet.add('100') ;
monSet.add('280') ;
console.log(monSet.size) ;