gpt4 book ai didi

javascript - 从对象中提取图像值

转载 作者:行者123 更新时间:2023-12-03 03:52:05 25 4
gpt4 key购买 nike

我有一个像这样的对象:

var obj = [
{
"id": 728,
"title": "A long day",
"images": {
"illustration": {
"title": "Preview",
"16x9": {
"1248x702": "https://example.com/image/225944d77559.jpg",
"1920x1080": "https://example.com/image/4546b05422594.jpg"
}
}
}
}
];

我正在尝试一段时间来获取 1920x1080值,但没有成功:

            alert(obj[0].title); //works 
alert(obj[0].images.illustration.title); // works
alert(obj[0].images.illustration.16x9.1920x1080); // doesn't work and break the code
alert(obj[0].images.illustration.'16x9'.'1920x1080'); // doesn't work and break the code

我需要你的帮助。我应该怎样做才能正确获取 1920x1080 条目?

最佳答案

使用括号:

var obj = [
{
"id": 728,
"title": "A long day",
"images": {
"illustration": {
"title": "Preview",
"16x9": {
"1248x702": "https://example.com/image/225944d77559.jpg",
"1920x1080": "https://example.com/image/4546b05422594.jpg"
}
}
}
}
];

console.log(obj[0].images.illustration['16x9']['1920x1080']);

关于javascript - 从对象中提取图像值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45118830/

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