[Vuejs]-How to access value of a JSON object whose key is value of another JSON object?

2👍

Just use bracket notation like so:

Obj1 = {"name":"John", "age":30, "car":null};
Obj2 = {"John":{"country":"america", "job":"Engineer"}}

Obj2[Obj1.name].country;
// or
Obj2[Obj1["name"]]["country"]

1👍

You can access object properties using the square bracket syntax.

object.property is equal to object["property"].

For your example, you can do

console.log(Obj2[Obj1.name]);

1👍

You can try the following
Obj2[Obj1['name']]['country']

Leave a comment