[英]Accessing an object inside an object
I'm trying to access an object inside an object but i have trouble figure out how.我正在尝试访问对象内的对象,但我无法弄清楚如何访问。
{
id: "335f",
symbol: "fr",
name: "nom",
categories: [
"Langue"
],
localization: {
fr: "bonjour",
en: "hello",
},
I would like to access 'fr' inside of 'localization';我想访问“本地化”中的“fr”;
I managed to console log data.localization but i can't access only the fr (it log everything)我设法控制台日志 data.localization 但我不能只访问 fr (它记录所有内容)
const [data, setData] = useState({ coin: [] });
useEffect(() => {
const fetchData = async () => {
const result = await axios(url);
setData(result.data);
};
fetchData();
}, []);
console.log(data.localization)
Just move console.log(data.localization)
inside async context, so:只需在异步上下文中移动
console.log(data.localization)
,所以:
useEffect(() => {
const fetchData = async () => {
const result = await axios(url);
setData(result.data);
console.log(result.data.localization);
};
fetchData();
}, []);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.