loop over the array and print out the values - Javascript Array Operation

Javascript examples for Array Operation:Array Element

Description

loop over the array and print out the values

Demo Code

ResultView the demo in separate window

<html lang="en">
   <head> 
      <title>Printing Array Values</title> 
   </head> 
   <body translate="no"> 
      <script>
      var arr = [1, 2, 3, [4, 5], 6, [7, 8, 9]], x, j;
for (x in arr) {/*  w  w w .  j  a  v  a  2s  . c o  m*/
  //check if value is array
  if(arr[x].constructor === Array) {

    for (j in arr[x]) {
      console.log(arr[x][j])
    }
  } else {
    console.log(arr[x])
  }
}
    
      </script>  
   </body>
</html>

Related Tutorials