Convert From JSON to Associative array - Javascript Array Operation

Javascript examples for Array Operation:Associative Array

Description

Convert From JSON to Associative array

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(){/*from w  ww . j a  v  a2 s  .  c  om*/
var text = '{ "employees" : [' +
'{ "firstName":"John" , "lastName":"Doe" },' +
'{ "firstName":"Anna" , "lastName":"Smith" },' +
'{ "firstName":"Peter" , "lastName":"Jones" } ]}';
var obj = JSON.parse(text);
console.log(obj);
console.log(obj.employees[0].firstName);
    }

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

Related Tutorials