How to iterate over every property of an object in javascript?

Posted by OverloadUT on Stack Overflow See other posts from Stack Overflow or by OverloadUT
Published on 2009-02-25T21:15:42Z Indexed on 2010/04/24 3:23 UTC
Read the original article Hit count: 230

Filed under:
|

Is there a way to iterate over every property of an object using the Prototype JavaScript framework?

Here's the situation: I am getting an AJAX response in JSON that looks something like this:

{foo: 1, bar: 2, barobj: {75: true, 76: false, 85: true}}

If I evaluate that json response in to a variable response, I want to be able to iterate over each property in the response.barobj object to see which indexes are true and which are false.

Prototype has both Object.keys() and Object.values() but oddly seems to not have a simple Object.each() function! I could take the results of Object.keys() and Object.values() and cross-reference the other as I iterate through one, but that is such a hack that I am sure there is a proper way to do it!

© Stack Overflow or respective owner

Related posts about prototype

Related posts about JavaScript