Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
94
rated 0 times [  97] [ 3]  / answers: 1 / hits: 23243  / 13 Years ago, sun, september 25, 2011, 12:00:00

Possible Duplicate:

Access the first property of an object






I have a javascript object like this:



var list = {
item1: a,
item2: b,
item3: c,
item4: d
};


Using reflection in JS, I can say list[item1] to get or set each member programmatically, but I don't want to rely on the name of the member (object may be extended). So I want to get the first member of this object.



If I write the following code it returns undefined. Anybody knows how this can be done?



var first = list[0]; // this returns undefined

More From » reflection

 Answers
3
 for(var key in obj) break;
// key is the first key here

[#89939] Thursday, September 22, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
minab

Total Points: 701
Total Questions: 104
Total Answers: 91

Location: Saint Pierre and Miquelon
Member since Fri, Jan 28, 2022
2 Years ago
;