Linked Questions

Popular Questions

Print set element in javascript

Asked by At

I am trying to print the set element through innerHTML, but I am not getting the desired result. While I tried with document.write(),it is printing but I want to use only innerHTML.

Here is my source code:

  <div id="demo"> </div>  
  <script type="text/javascript">
     var i, item;
     var setObj1 = new Set();

     for (item of setObj1.values())
     document.getElementById('demo').innerHTML="The set value is: "+ item;         

Output: 4

Desire output: 0 1 2 3 4

Please suggest me how to use innerHTML to print the output.I have tried console log and document.write(), they are working.

Related Questions