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