Working with Nested Objects in JavaScript

by Jagadish Pulakhandam on 8/30/2012 1:31:49 PM
Rated 0 from 0 votes
Brief: Demonstrate on defining and accessing nested objects (from parent objects) in JavaScript
Posted to: Advanced JavaScript Programming/Development tutorials/videos- Object Oriented Programming
Add to DiggAdd to del.icio.usAdd to FURLAdd to RedditAdd to YahooAdd to BlinklistAdd to GoogleAdd to ma.gnoliaAdd to ShadowsAdd to Technorati

Demonstrates the following:
  • How to create an anonymous (parent) object using JavaScript
  • How to create a nested object (in an already existing object) and assign a property name to it
  • How to access the properties of a nested object from parent object.
Source Code:

01.<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
05.    <title></title>
06.    <script type="text/javascript">
07.        //DEMO: nested objects
09.        var oEmp = {
10.            Empno:1001,
11.            Ename:"Jag",
12.            //an object inside "oEmp" - nested object
13.            Dept:{
14.                Deptno:10,
15.                Dname:"IT"
16.            }
17.        };
19.        //accessing property of nested object from parent object
20.        alert(oEmp.Ename + " works in " + oEmp.Dept.Dname);
21.    </script>

Join the .NET Code Central Community and join the discussion!
Signing-up is FREE and quick. Do it now, we want to hear your opinion

Rated 0 from 0 votes ( login  to rate)
DotnetKicks DotnetKicksDe DotNetShoutout

Attachments / Source Code
You need to Login or Join for FREE to download the following