JavaScript Set Object

Full Stack Web Development Courses with Real-time projects Start Now!!

Program 1

<html>
    <head>
        <title>Math Object Methods</title>
        <script type="text/javascript">
                   document.writeln("<center>")
                    document.writeln("<h2>")
                    const myset=new Set(["Indore","Pune","Bhopal","Delhi","Ujjain",123,true,12.55])
                      document.writeln("Size of Set: "+myset.size)
                      
                      myset.forEach(element => 
                    {
                        document.writeln("<br>"+element)    
                    });      
                      myset.clear()
                      
                    //document.writeln(myset.delete("Pune"))
                    document.writeln("<br>---------------------------")
                    document.writeln("<br>Size of Set: "+myset.size)
                    myset.forEach(element => 
                    {
                        document.writeln("<br>"+element)    
                    });      

                        //Searching 

                    // mystr=prompt("Enter an element for search")                        
                    
                    // if(myset.has(mystr))
                    //   document.writeln("<br> Searching success")
                    // else
                    // document.writeln("<br> Searching not success")

                    //    myitr=myset.keys() 
                    //    //document.writeln("<br>"+myitr) 
                    //   for(let x of myitr)
                    //   {
                    //     document.writeln("<br>"+x) 
                    //   }
                                  
                                       
                    
                    //    myitr=myset.values() 
                    //    //document.writeln("<br>"+myitr) 
                    //   for(let x of myitr)
                    //   {
                    //     document.writeln("<br>"+x) 
                    //   }


                    //  myset.forEach(function(value){
                    //     document.writeln("<br>"+value)
                    // })

                    //  for(let i=1;i<=5;i++) 
                    //  {
                    //     let x=prompt("Enter elements")
                    //     myset.add(x)
                    //  }
                    // myset.forEach(element => 
                    // {
                    //     document.writeln("<br>"+element)    
                    // });
                    document.writeln("<h2>")
                   document.writeln("</center>")
         </script>
    </head>
    <body>
        <center>
        </center>   
         
    </body>
</html>

 

Did we exceed your expectations?
If Yes, share your valuable feedback on Google

courses
Image

DataFlair Team

DataFlair Team provides high-impact content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. We make complex concepts easy to grasp, helping learners of all levels succeed in their tech careers.

Leave a Reply

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