Click here to hide categories Click here to show left categories

User: Home          welcome : Guest          Log In / Register here     




How do I access properties of a javascript object if I do not know the names

For example we have object like blow:

var data = { Name: 'rohit', Value: '0' };

Properties can be accessed by the property name like below

data.Name

data["Value"]

Now we want to view all properties of Object, then we will write

for (var key in data) { 
  alert(key);
}

or same can be achieve with below function:

for each (var value in data) {
  alert(value);
}
Share this article   |    Print    |    Article read by 3430 times
Author:
Rohit kakria
I am software developer
Related Articles: No related article
Related Interview Questions: No related interview question