gpt4 book ai didi

javascript - 修改javascript中的嵌套对象

转载 作者:行者123 更新时间:2023-11-28 03:51:38 25 4
gpt4 key购买 nike

有人可以帮助我访问嵌套在 hello 中的对象吗?我尝试过greetings.hello.portuguese,但它未定义

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

最佳答案

greentings 中有两个数组,分别是 hellogoodbye,如果您想访问葡萄牙语,您需要从索引为0的第一个数组中获取它。

代码

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

关于javascript - 修改javascript中的嵌套对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47952230/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com