I have an object which will only have one property (own property). What is the easiest way to access that property's value?
Something like:
value = obj[<firstProperty>];
I know I can write a function or a for loop to do this but am asking if there is a shorter way.
for (p in obj) {
if (obj.hasOwnProperty(p)) {
value = obj[p];
}
}
I won't know the name of the property up front. I only know that there will only be one property directly on the object.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…