Javascript Set Iterate

Description

Javascript Set Iterate

let mySet = new Set();

mySet.add(1);//from   w w w.j a v  a 2s . c  o m
mySet.add(5);
mySet.add(5);

// iterate over items in set
for (let item of mySet){
   console.log(item);
}

for (let item of mySet.keys()){
   console.log(item);   
}
 
for (let item of mySet.values()){
   console.log(item);
}

for (let [key, value] of mySet.entries()) {
   console.log(key);    
}



PreviousNext

Related