在javascript中修改嵌套对象

时间:2017-12-23 11:47:25

标签: javascript

有人可以帮助我访问嵌套在hello中的对象吗? 我试过greetings.hello.portuguese,但是undefined

const greetings = {
  hello: [{
    english: 'hi',
    french: 'bonjour',
    portuguese: 'oi'
  }],
  goodbye: [{
    english: 'bye',
    french: 'au revoir',
    portuguese: 'tchau'
  }]
};

1 个答案:

答案 0 :(得分:0)

greentings 内有两个数组 hello goodbye ,如果你想要访问 portuguese ,您需要从第一个索引为0的数组中获取它。

<强> CODE

&#13;
&#13;
 const greetings = {
  hello: [{
    english: 'hi',
    french: 'bonjour',
    portuguese: 'oi'
  }],
  goodbye: [{
    english: 'bye',
    french: 'au revoir',
    portuguese: 'tchau'
  }]
};
console.log(greetings.hello[0].portuguese);
&#13;
&#13;
&#13;