从json objec使用金额获得一个月

웃웃웃*_*웃웃웃 0 javascript json

我有一个变量,它是存储差异.amount喜欢147421
,我想找到这个金额要显示有monthJSON

我的JSON对象如下所示:

var array = [
    {
        amount: 12185,
        month: "JANUARY",
        year: "2010"
    },
    {
        amount: 147421,
        month: "MAY",
        year: "2010"
    },
    {
        amount: 2347,
        month: "AUGUST",
        year: "2010"
    }
];
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?.
选择月份在哪里amount == 12185

小智 6

您可以使用过滤数据 .filter

var result = array.filter(function(item) {
    return item.amount == 12185;
});
Run Code Online (Sandbox Code Playgroud)

DEMO

  • 哇!我从来没有听说过这种过滤方法!1起:) (4认同)