in runtime i will have a dynamic dictionary object return to me
e.g var objectFromApi = {"A ":"I am A","B":"I am B","C":"I am C"}
i cannot do objectFromApi ["A"] to get the value, since i won`t able to know the key.
is there a way to print all the key and its value?
is there something like
for(j=0;j<objectFromApi.length;j++)
{
console.debug(objectFromApi[j].Key +" " + objectFromApi[j].Value);
}
Thanks
in runtime i will have a dynamic dictionary object return to me
e.g var objectFromApi = {"A ":"I am A","B":"I am B","C":"I am C"}
i cannot do objectFromApi ["A"] to get the value, since i won`t able to know the key.
is there a way to print all the key and its value?
is there something like
for(j=0;j<objectFromApi.length;j++)
{
console.debug(objectFromApi[j].Key +" " + objectFromApi[j].Value);
}
Thanks
Share Improve this question asked Jun 27, 2012 at 8:27 jojojojo 13.9k36 gold badges95 silver badges126 bronze badges2 Answers
Reset to default 7for(var name in objectFromApi )
{
if (objectFromApi.hasOwnProperty(name))
{
}
}
http://jsfiddle/V6t6Y/
In ECMA 5 you can also use
var keys = Object.keys(objectFromAPi)
which will return
["A ", "B", "C"]
then you can iterate over the array like you normally would
for(var i = 0; i < keys.length; i++){
// do something with the value
// objectFromApi[keys[i]]
}