-4

I wanna get a value in object.

const object = {
      foo: {
        hoge: []
      }
    }
    
console.log(object["foo"]); //-> {hoge:[]}
console.log(object["foo"]["hoge"]); //-> []

? is String.

Is there a person who can solve it?

I have a answer. Using eval

console.log(eval("object.foo.hoge]")); //-> []

but, I do not want to use eval

Thanks.

Junya Kono
  • 1,121
  • 3
  • 10
  • 16

1 Answers1

0

object["foo"]["hoge"] will do what you want. Note that because the keys are valid identifiers, you can use the shorthand attribute access syntax: object.foo.hoge.

cdhowie
  • 158,093
  • 24
  • 286
  • 300