“Set JavaScript berisi” Kode Jawaban

set js

// Use to remove duplicate elements from the array 

const numbers = [2,3,4,4,2,3,3,4,4,5,5,6,6,7,5,32,3,4,5]

//spreading numbers of the object into an array using the new operator
console.log([...new Set(numbers)]) 

// [2, 3, 4, 5, 6, 7, 32]
Happy Hyena

diatur dalam JavaScript

let mySet = new Set()

mySet.add(1)           // Set [ 1 ]
mySet.add(5)           // Set [ 1, 5 ]
mySet.add(5)           // Set [ 1, 5 ]
mySet.add('some text') // Set [ 1, 5, 'some text' ]
let o = {a: 1, b: 2}
mySet.add(o)

mySet.add({a: 1, b: 2})   // o is referencing a different object, so this is okay

mySet.has(1)              // true
mySet.has(3)              // false, since 3 has not been added to the set
mySet.has(5)              // true
mySet.has(Math.sqrt(25))  // true
mySet.has('Some Text'.toLowerCase()) // true
mySet.has(o)       // true

mySet.size         // 5

mySet.delete(5)    // removes 5 from the set
mySet.has(5)       // false, 5 has been removed

mySet.size         // 4, since we just removed one value

console.log(mySet)
// logs Set(4) [ 1, "some text", {…}, {…} ] in Firefox
// logs Set(4) { 1, "some text", {…}, {…} } in Chrome
Yellowed Yak

Set.Contains di JavaScript

const set = new Set();

set.add(1);
set.add(2);
set.add(3);

console.log(set.has(2));  //true
console.log(set.has(4)); //false
Nasty Newt

Set JavaScript berisi

function display()
{
for(llet i=1;i<5;i++)
{
console.log(i);
}
console.log(i);
}
display()
Different Dolphin

Jawaban yang mirip dengan “Set JavaScript berisi”

Pertanyaan yang mirip dengan “Set JavaScript berisi”

Lebih banyak jawaban terkait untuk “Set JavaScript berisi” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya