[Super Tip!] How to loop or iterate over an object’s key/value pair.
| No Comments »Problem: Help! Is it possible to loop or iterate through each object’s key/value pair like an array? Answer: A very useful trick for iterating over objects is the use of (for x in object), with this you can completely use objects as array!
myObject = {
“this” : “value1″,
“is” : “value2″,
“awesome” : “value3″
}
for (x in myObject)
alert(‘key : ‘ + x + ‘ / value : ‘ + myObject[x]);


Leave a Reply