-3

I have following Object:

bots: {
    bot_1: {
      [...]
    },
    bot_2: {
      [...]
    },
    bot_3: {
      [...]
    }
    ...
},

How could I get the name of the first child? In this case 'bot_1'. Thanks!

EDIT: I should have searched a bit more since it is a pretty basic question. I tried searching for the answer but I couldn't find it because I didn't know that it is called "property". Anyways, thanks for your help

user2324232322
  • 303
  • 2
  • 6
  • 16

1 Answers1

2

You can do this

bots[Object.keys(bots)[0]];

to get the first key of your object. However, you may not get bot_1 always since the keys are unordered

Vimalraj Selvam
  • 2,155
  • 3
  • 23
  • 52