gpt4 book ai didi

javascript - 如何通过lodash从json对象获取两个值?

转载 作者:行者123 更新时间:2023-11-28 17:59:31 32 4
gpt4 key购买 nike

我是 json 和 lodash 的新手。我想从 Json 中获取两个值。但现在我只能从返回中获得一个值。所以我想把这两种值(value)观结合起来。

[
{
"_id": {
"mm": 2,
"hr": 9,
"sl": 1
},
"tot": 188
},
{
"_id": {
"mm": 2,
"hr": 4,
"sl": 3
},
"tot": 622
},
{
"_id": {
"mm": 2,
"hr": 12,
"sl": 5
},
"tot": 484


}]
<小时/>
_.map(resp.data,function(res){ return res._id.hr})

我还想通过“hr”获取 sl 值,例如 9:1、4:3、12:5。 (小时:sl)。

最佳答案

您可以返回一个包含您想要的所有数据的对象,例如:

var results =_.map(a, function(res) { 
return { hr: res._id.hr, sl: res._id.sl };
});

Example on JSBin

关于javascript - 如何通过lodash从json对象获取两个值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43828739/

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