check if value is array - Javascript Array Operation

Javascript examples for Array Operation:Array Element

Description

check if value is array

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 2 s  .com*/
  //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