-1

I have this:

var myObj = {
    first: "str",
    second:{
    16: {option_one: "...", option_two: "..."},
    31: {option_one: "...", option_two: "..."},
    }
};

I can't change that code. But i need to get 16: {...}. JS doesn't allow to do myObj.second.16. Can i do it with numeric name?

Rimarx
  • 543
  • 3
  • 15

1 Answers1

1

Use [ and ] around 16:

var myObj = {
    first: "str",
    second:{
    16: {option_one: "...", option_two: "..."},
    31: {option_one: "...", option_two: "..."},
    }
};

console.log(myObj.second[16])
Sash Sinha
  • 18,743
  • 3
  • 23
  • 40