0

I have this JSON:

let myJson = 
{
    'name':'John Doe'
    'address': {
        'country':'CN'
        'city':'Toronto'
    }
}

I can select the values by

console.log(myJson['name'])
console.log(myJson['address']['country'])

I'm trying to do it this way

function getValue(key) {
    console.log(myJson[key]);
}

//this works
getValue('name');

I can get the name value but how do I get the nested ones with the function above?

askwer
  • 163
  • 13

0 Answers0