Traverse Array Object Using JavaScript Example


Share:
Published By: Admin, Published On: Oct 30, 2021, Category: Javascript


Hello Friends,

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

Here i will give you many example how to traverse array object using javascript.

Example : 1
<!DOCTYPE html>
<html>
    <head>
    	<title>Traverse Array Object Using JavaScript Example - MyWebtuts.com</title>
    </head>
    <body>
        <h2>Traverse Array Object Using JavaScript Example - MyWebtuts.com</h2>
        <script>
            // declare and initialize an array with integer values
            var intarray = [77,65,48,97,22,49,35]; 
            var i=0;

            document.write("Elements in array : <br>");
            //traverse the array using while loop
            while( i< intarray.length) {
               //display the array elements
               document.write(intarray[i] + "<br>");
               i++;
            }
        </script>
    </body>
</html>
Output :
Elements in array :
77
65
48
97
22
49
35
Example : 2
<!DOCTYPE html>
<html>
    <head>
        <title>Traverse Array Object Using JavaScript Example - MyWebtuts.com</title>
    </head>
    <body>
        <h2>Traverse Array Object Using JavaScript Example - MyWebtuts.com</h2>
        <script>
            // declare an array and provide value in it   
            var msg = ["Traverse", " Array", " Object", " JavaScript"];   
            var index = 0;  

            //call the user-defined function with array  
            msg.forEach(traversearr);  

            //definition of user-defined function  
            function traversearr(ele, index)  
            {  
                //display the array elements using index   
                document.write(ele);  
            }  
        </script>
    </body>
</html>
Output :
Traverse Array Object JavaScript

It will help you...

Share: