gpt4 book ai didi

javascript - Object.entries 未返回预期结果

转载 作者:行者123 更新时间:2023-12-02 21:41:39 24 4
gpt4 key购买 nike

我有一个如下所示的数组:

sim_data = [
{
"thumb_name": "Panel_BG_light",
"thumb_file": "/media/media/3938493866/3938493866.jpg",
"thumb_date": "2020-02-17T21:52:58.753408Z"
},
{
"thumb_name": "Panel_BG_dark",
"thumb_file": "/media/media/1247845432/1247845432.jpg",
"thumb_date": "2020-02-22T11:13:28.937390Z"
}
]
<小时/>

我使用这个函数从数组中获取图像:

var panel_bg_light_;
var panel_bg_dark_;
var panel_background_light = sim_data[0];
var panel_background_dark = sim_data[1];

Object.entries(panel_background_light).forEach(([key, value]) => {
panel_bg_light = value["thumb_file"];
panel_bg_light_ = JSON.stringify(panel_bg_light);
return panel_bg_light_;
});

Object.entries(panel_background_dark).forEach(([key, value]) => {
panel_bg_dark = value["thumb_file"];
panel_bg_dark_ = JSON.stringify(panel_bg_dark);
return panel_bg_dark_;
});

我控制台记录了 panel_background_light 的类型,它是一个对象,那么为什么我不能像这样访问 Object.entries

谢谢

最佳答案

Object.entries 返回对象键/值对的数组。所以输出:

Object.entries({
"thumb_name": "Panel_BG_light",
"thumb_file": "/media/media/3938493866/3938493866.jpg",
"thumb_date": "2020-02-17T21:52:58.753408Z"
}
)

看起来像:

[
["thumb_name", "Panel_BG_light"],
["thumb_file", "/media/media/3938493866/3938493866.jpg"],
["thumb_date", "2020-02-17T21:52:58.753408Z"]
]

如果您只想获取“thumb_file”的值,为什么不直接访问它呢?即。

var panel_bg_light_ = sim_data[0]['thumb_file'];
var panel_bg_dark_ = sim_data[1]['thumb_file'];

关于javascript - Object.entries 未返回预期结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60351917/

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