Consider, I have this object:
var ob = {
"page1.html" : {...},
"page2.html" : {...},
"page3.html" : {...}
}
I am unable to change this to an array, I don’t have access to that, what I’d like to know is if it is safe to access the object properties by index, so:
var obVal = ob[0]; // reliably returns "page1.html"'s value every time
I know that a for each loop shouldn’t be used in this situation because the values are hashed or something? But reference by index might be ok?
No,
ob[0]won’t even work – it will giveundefined. In fact if your object was:ob[0]will give you"blah".A for-each loop is the right tool for this situation, but you should just check that each index in the loop actually belongs to the object, and not to a parent: