gpt4 book ai didi

javascript - 使用 amount 从 json 对象获取一个月

转载 作者:行者123 更新时间:2023-11-28 11:56:53 24 4
gpt4 key购买 nike

我有一个变量,它是存储差异。 金额147421
我想找到这个金额,希望在 JSON

中显示 month

我的 JSON 对象如下所示:

var array = [
{
amount: 12185,
month: "JANUARY",
year: "2010"
},
{
amount: 147421,
month: "MAY",
year: "2010"
},
{
amount: 2347,
month: "AUGUST",
year: "2010"
}
];

我该如何做到这一点?
选择金额 == 12185

的月份

最佳答案

您可以使用.filter过滤数据

var result = array.filter(function(item) {
return item.amount == 12185;
});

<强> DEMO

关于javascript - 使用 amount 从 json 对象获取一个月,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21180463/

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