Javascript Set clear()

Introduction

The Javascript Set clear() method removes all elements from a Set object.

It returns undefined.

mySet.clear();

Using the clear method

var mySet = new Set();
mySet.add(1);/* ww  w .ja  va 2s .  c om*/
mySet.add('foo');
console.log(mySet);

console.log(mySet.size);
console.log(mySet.has('foo')); // true

mySet.clear();

console.log(mySet.size);       // 0
console.log(mySet.has('bar'));  // false



PreviousNext

Related