Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
0
rated 0 times [  1] [ 1]  / answers: 1 / hits: 35699  / 8 Years ago, tue, march 1, 2016, 12:00:00

Say if you were unable to access a certain item inside an object through dot notation like objectName.objectItem i.e. it has random name al the time. Is there a way to alternatively access it like second item?



how to get item2 from this object by only knowing that it is second item there?:



something: {
item1: text,
item2: text,
item3: text:,
...
}

More From » json

 Answers
65

Order of keys are not fixed in javascript object.



You can try



var secondKey = Object.keys(something)[1]; //fetched the key at second index
alert(something[secondKey ]);

[#63099] Saturday, February 27, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
janettejordynm

Total Points: 550
Total Questions: 94
Total Answers: 98

Location: Senegal
Member since Fri, Aug 21, 2020
4 Years ago
janettejordynm questions
Tue, Nov 24, 20, 00:00, 4 Years ago
Sat, May 23, 20, 00:00, 4 Years ago
Mon, Apr 6, 20, 00:00, 4 Years ago
Tue, Feb 18, 20, 00:00, 4 Years ago
;