Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
Clearing the set using Javascript
The clear method is pretty straightforward. We can just reassign the container variable to a new object and the set will now be empty. This can be implemented as follows −
Example
clear() {
this.container = {};
}
You can test this using −
Example
const testSet = new MySet(); testSet.add(1); testSet.add(2); testSet.add(5); testSet.display(); testSet.clear(); testSet.display();
Output
This will give the output −
{ '1': 1, '2': 2, '5': 5 }
{ } Advertisements
