Click here to Skip to main content
15,908,634 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have an object as shown below.
var attr={node:1;value:"2"
}
I know for each prototype can be used for array? the same can used for object array? If so is there any way to check whether a value exist in the object array?
Posted

1 solution

First there is a mistake in syntax.

var attr={node:1;value:"2"}

use ,

I think forEach is available only for Arrays.

C#
{node:1,value:"2"}
is an object. To make it an array, just wrap it with "[]"

C#
[{node:1,value:"2"}]


Check this and let me know... below is a working example tested with Firefox.

JavaScript
var obj = [{name:"John",age:25}];
    obj.forEach(function(person){
      alert(person.name+" is "+person.age+" years old");
    });
 
Share this answer
 
Comments
manjukakkadath 19-Oct-11 1:07am    
How to fetch each value of object if i add [] to the value?Please advice.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900