gauthi24
10-05-2011, 03:31 AM
I'm writing a program that involves a network of interconnected nodes (or simply objects in my example below). It depends on being able to access properties of an object's linked objects (a bit oddly worded, sorry)...
Problem is I'm not sure how to properly access those properties... see below please.
<script>
//This is an example of a problem im having in my own code...
//I want to access the name of the object within the links array wintin the object...
var objA = {name: "Object A", links: [objB, objC]};
var objB = {name: "Object B", links: [objC, objD, objE]};
var objC = {name: "Object C", links: [objB]};
var objD = {name: "Object D", links: [objE]};
var objE = {name: "Object E", links: [objD]};
//ex: I want to access the name of Object A's first link...
console.log(objA.links[0].name);
</script>
I'm hoping to get "Object B"...
But instead I get: TypeError: Result of expression 'objA.links[0]' [undefined] is not an object.
Is there another way around this? Any thoughts are appreciated.
Problem is I'm not sure how to properly access those properties... see below please.
<script>
//This is an example of a problem im having in my own code...
//I want to access the name of the object within the links array wintin the object...
var objA = {name: "Object A", links: [objB, objC]};
var objB = {name: "Object B", links: [objC, objD, objE]};
var objC = {name: "Object C", links: [objB]};
var objD = {name: "Object D", links: [objE]};
var objE = {name: "Object E", links: [objD]};
//ex: I want to access the name of Object A's first link...
console.log(objA.links[0].name);
</script>
I'm hoping to get "Object B"...
But instead I get: TypeError: Result of expression 'objA.links[0]' [undefined] is not an object.
Is there another way around this? Any thoughts are appreciated.