0

I need to access to object properties by string with another object In php you can reach that like if array $b = 't';$a->$b; is the same as $a->t

var obj = {
    title : 'spider'
}

var hero = {
    spider : 'is a hero'
}

console.log( hero.spider );//works fine
console.log( hero.obj.title );//i need the same result, from variable (obj)

how can i do that

Asylzat
  • 197
  • 5
  • 17

1 Answers1

1
console.log(hero[obj.title])

I think this should work.

Phillip K
  • 237
  • 1
  • 8