C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
JavaScript Set add() methodThe JavaScript Set add() method is used to add an element to Set object with a specified value. Each element must have a unique value. SyntaxThe add() method is represented by the following syntax: setObj.add(value) Parametervalue - It represents the value to be added. ReturnThe Set object. JavaScript Set add() method exampleHere, we will understand add() method through various examples. Example 1Let's see an example to add value of elements to set object. <script> var set = new Set(); set.add("jQuery"); set.add("AngularJS"); set.add("Bootstrap"); for (let elements of set) { document.writeln(elements+"<br>"); } </script> Output: jQuery AngularJS Bootstrap Example 2In this example, we will add the elements to set object in chainable form. <script> var set = new Set(); set.add("jQuery").add("AngularJS").add("Bootstrap"); for (let elements of set) { document.writeln(elements+"<br>"); } </script> Output: jQuery AngularJS Bootstrap
Next TopicJavaScript Set clear() Method
|