Skip to content

JavaScript Set of objects

  • by

You can create a set and add object to the set. JavaScript Set of objects loot like same as a normal object but entries have a value of the object.

JavaScript Set of objects

A simple example code creates a set and add the object to it.

<!DOCTYPE html>
<html>
<body>

  <script>
   let s = new Set();
   let a = {1: "A"};
   let b = {2: "B"};

   s.add(a);
   s.add(b)

   console.log(s)
   console.log(s instanceof Set)
   console.log(s instanceof Object)
   console.log(s instanceof Array)
 </script>
</body>
</html>

Output:

JavaScript Set of objects

Do comment if you have any doubts or suggestions on this JS set topic.

Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.

OS: Windows 10

Code: HTML 5 Version

Leave a Reply

Your email address will not be published. Required fields are marked *