As pointed out in all of the comments, there is now way to guarantee the "first three" properties of an object in JS, because it has no inherent order in an Object
. As such, if you were to use a for (i in obj) {}
loop and put a counter in it to track the number of loops that you'd been through, so that you could stop at 3 (for example), different browsers could return you three different properties.
So . . . try storing your data like this . . . it is similar to what you are using and will allow you to support numerating your data more easily:
var rooms = [
{room: "room1",
number: 10},
{room: "room2",
number: "25"},
{room: "room3",
number: "15"},
{room: "room4",
number: "1"},
{room: "room5",
number: "10"},
{room: "room6",
number: "181"}
];
rooms[0].room
would get you room1
, rooms[0].room
would equal 10
. . . loop through as many as you want after that, to get the next ones in line.
Alernately, if the "roomn" values are just being used to enumerate the values, do you need them at all? You could use a simple array:
var rooms = [10, 25, 15, 1, 10, 181];
With that, rooms[0]
would equal 10
, rooms[1]
would equal 25
, etc.
In either case, looping through (or slicing off) the first three entries would be easily supported.