How To Use IN Operator In JavaScript Example?


Share:
Published By: Admin, Published On: Nov 09, 2021, Category: Javascript


Hello Friends,

Now let's see example of how to get IN operator example. We will check how to get IN operator. This is a short guide on get IN operator in javascript. Let's get started with how to get IN operator in javascript.

Here i will give you many example how to get IN operator using javascript.

Example : 1
<!DOCTYPE html>
<html>
    <head>
        <title>How To Use IN Operator In JavaScript Example? - MyWebtuts.com</title>
    </head>
    <body>
        <h3>How To Use IN Operator In JavaScript Example? - MyWebtuts.com</h3>
        <h4> Click the below button to see the output. </h4>
        <button onclick = "test()"> Click me </button>

        <script>
            function test(){
                const stream = { a1: 'BCA', a2: 'Bsc.it', a3: 'BBA', v4: 'MCA' };
                document.write(" <b> Is the value 'a1' in stream array? </b> ", 'a1' in stream, "<br>");
                document.write(" <b> Is the value 'a3' in stream array? </b> ", 'a3' in stream, "<br> <br>");
                document.write("After applying <b> delete stream.a3; </b> <br> <br> ");
                delete stream.a3;
                document.write(" <b> Now, Is the value 'a3' in stream array? </b> ", 'a3' in stream, "<br><br>");
            }
        </script>
    </body>
</html>  
Output :
Is the value 'a1' in stream array? true
Is the value 'a3' in stream array? true

After applying delete stream.a3;

Now, Is the value 'a3' in stream array? false
Example : 2
<!DOCTYPE html>
<html>
    <head>
        <title>How To Use IN Operator In JavaScript Example? - MyWebtuts.com</title>
    </head>
    <body>
        <h3>How To Use IN Operator In JavaScript Example? - MyWebtuts.com</h3>
        <h4>Click the below button to see the output.</h4>
        <button onclick = "d1()">Click me</button>

        <script>
            function d1(){
                const subj = [ 'JavaScript', 'Laravel', 'PHP','JQuery' ];
                document.write(" <b> Is the value 0 in subject array? </b> ", 0 in subj, "<br>");
                document.write(" <b> Is the value '2' in subject array? </b> ", 1 in subj, "<br><br>");
                document.write(" <b> Is the value '4' in subject array? </b> ", 4 in subj, "<br><br>");
            }
        </script>
    </body>
</html>   
Output :
Is the value 0 in subject array? true
Is the value '2' in subject array? true

Is the value '4' in subject array? false

It will help you...

Share: