set

Estimated reading time: 2 minutes

entries & add

'use strict';
let users = new Set();
users.add({
  name: 'kamal',
  age: 21
});
users.add({
  name: 'jamal',
  age: 23
})
for(let [user] of users.entries()){
  console.log((user.name));
}

forEach

'use strict';
let users = new Set();
users.add({
  name: 'kamal',
  age: 21
});
users.add({
  name: 'jamal',
  age: 23
})
users.forEach ((user) => {
  console.log(user.name);
})

size

'use strict';
let users = new Set();
users.add({
  name: 'kamal',
  age: 21
});
users.add({
  name: 'jamal',
  age: 23
});
console.log(users.size);

clear

'use strict';
let users = new Set();
users.add({
  name: 'kamal',
  age: 21
});
users.add({
  name: 'jamal',
  age: 23
})
users.clear();
users.forEach ((user) => {
  console.log(user.name);
})

delete

'use strict';
let users = new Set();
users.add({
  name: 'kamal',
  age: 21
});
users.add({
  name: 'jamal',
  age: 23
})
users.forEach ((user) => {
  if(user.name === 'kamal') {
    users.delete(user);
  }
})

users.forEach((user) => {
  console.log(user.name);
})
es, es6, js