gpt4 book ai didi

javascript - 返回 javascript 对象的特定值

转载 作者:行者123 更新时间:2023-11-30 14:21:04 25 4
gpt4 key购买 nike

我有一个脚本将其返回为“r2”:

{
waitSeconds: 0,
runSeconds: 0,
report: {
data: [{
breakdown: [{}],
breakdownTotal: ["608674"],
day: 1,
month: 10,
name: "Mon. 1 Oct. 2018",
year: 2018,
}, {
name: "Tue. 2 Oct. 2018",
year: 2018,
month: 10,
day: 2,
breakdown: [{}],
breakdownTotal: ["123456"]
}, {
name: "Wed. 3 Oct. 2018",
year: 2018,
month: 10,
day: 3,
breakdown: [{}],
breakdownTotal: ["123456"]
}, {
name: "Thu. 4 Oct. 2018",
year: 2018,
month: 10,
day: 4,
breakdown: [{}],
breakdownTotal: ["123456"]
}, ],
elements: [{}],
metrics: [{}],
}
}

我正在 try catch 两件事并以以下格式返回它们:

[X,Y,Z,ETC]

我已经能够使用这段代码捕获这一天:

const days = r2.report.data.map(obj => obj.day);

但是,当我尝试获取 breakdownTotal(即 608674)时

const metric = r2.report.data.map(obj => obj.breakdownTotal);

它返回这个:

[Array(1), Array(1), Array(1), Array(1)]

如何让它返回 breakdownTotal 值?

最佳答案

您想要分割数组的第一个值而不是数组本身,对吗?

const metric = r2.report.data.map(obj => obj.breakdownTotal[0]);

试试这个?

关于javascript - 返回 javascript 对象的特定值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52740770/

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