Syntax error Set.clear() function in JavaScript

Set.clear() function in JavaScript



The clear() function of the Set object removes all elements from the current Set object.

Syntax

Its Syntax is as follows

setObj.clear()

Example

 Live Demo

<html>
<head>
   <title>JavaScript Example</title>
</head>
<body>
   <script type="text/javascript">
      const setObj = new Set();
      setObj.add('Java');
      setObj.add('JavaFX');
      setObj.add('JavaScript');
      setObj.add('HBase');
      setObj.clear();
      document.write("Contents of the Set:");
      for (let item of setObj) {
         document.write(item);
         document.write("<br>");
      }
   </script>
</body>
</html>

Output

Contents of the Set:
Updated on: 2020-06-25T12:52:59+05:30

563 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements