-2

Below are two objects:

let x = {y: 'z'} and let a = {z: 'b'}

I want to access a.{property}, where property is the the value of x.y

Please guide me.

user3980196
  • 493
  • 1
  • 5
  • 14

1 Answers1

1

Use bracket notation if you want to use property dynamically

Use a[x.y]. Please find example below:

let x = {y: 'z'};
let a = {z: 'b'};

console.log(x.y)
console.log(a[x.y]); // Final result

Please use this link to study about accessing object properties

Jasdeep Singh
  • 7,901
  • 1
  • 11
  • 28