JavaScript Code


JavaScript Set clear()


Set clear() method

Set clear() method is used to clear the contents of the set.

mySet.clear();
  • mySet is a set object.
  • entries is method name.

The clear() method returns undefined value.

Examples

1. Clear all the elements of the vowels set.

const vowels = new Set(['a', 'e', 'i', 'o', 'u']);
console.log('vowels : ' + [...vowels]);
vowels.clear();
console.log('vowels : ' + [...vowels]);

Copyright @2022