Get number of arrays from an object - Javascript Object

Javascript examples for Object:Reflection

Description

Get number of arrays from an object

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){//  w  ww.  java  2s .  com
var data = { Name:['a','b'], Na:['cd','ef'], Age:{a: 12}, Address:{a: 'asdf'} }
var numberOfArrays = Object.keys(data).filter(function(key) {
    return data[key] instanceof Array;
}).length;
console.log(numberOfArrays);
    }

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials