/ Published in: JavaScript
Javascritp object notation
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<!--<Simple way understanding JSON, Seems to be a very good concept for using objects in JS Multi dimensional arrays>--> <!--By Shashikanth--> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> <script type="text/javascript"> var employees = { "accounting" : [ // accounting is an array in employees. { "firstName" : "John", // First element "lastName" : "Doe", "age" : 23 }, { "firstName" : "Mary", // Second Element "lastName" : "Smith", "age" : 32 } ], // End "accounting" array. "sales" : [ // Sales is another array in employees. { "firstName" : "Sally", // First Element "lastName" : "Green", "age" : 27 }, { "firstName" : "Jim", // Second Element "lastName" : "Galley", "age" : 41 } ] // End "sales" Array. } // End Employees document.writeln(employees.accounting[1].firstName + ' - ' + employees.accounting[0].lastName); </script> </head> <body> </body> </html>