Question:

Javascript objects.....?

by  |  earlier

0 LIKES UnLike

How/can I get the child nodes from an object variable?

eg

var example = new Object()

example.child_1 = true

example.child_2 = false

How do I get the amount of child nodes the object "example" has?

I have tried: object.childNodes[] and object.firstChild but these don't seem to work the same as when an object is a tag element.

Thanks for your help,

Colin

ps sorry for the bad terminology - I'm new to using objects in js

 Tags:

   Report

1 ANSWERS


  1. var example = {};   // same as var example = new Object();

    example.child1 = 1;

    example.child2 = 2;

    for (var child in example)

    {

    document.write("example." + child + " = " + example[child] + "<br/>");

    }

    The for...in statement is pretty useful for situations such as this.

Question Stats

Latest activity: earlier.
This question has 1 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.