Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/382.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JavaScript:如何过滤字典中的数据_Javascript - Fatal编程技术网

JavaScript:如何过滤字典中的数据

JavaScript:如何过滤字典中的数据,javascript,Javascript,我在JS中有以下对象: [ { "financial_year":1, "mainline_revenue":18743.0, "regional_revenue":2914.0, "other_revenue":3198.0, "non_operating_items":-1983.0 }, { "financial_year":2, "mainline_revenue":20218.0, "regional_reve

我在JS中有以下对象:

[
  {
    "financial_year":1,
    "mainline_revenue":18743.0,
    "regional_revenue":2914.0,
    "other_revenue":3198.0,
    "non_operating_items":-1983.0
  },
  {
    "financial_year":2,
    "mainline_revenue":20218.0,
    "regional_revenue":3131.0,
    "other_revenue":3394.0,
    "non_operating_items":-3233.0
  },
  {
    "financial_year":3,
    "mainline_revenue":30802.0,
    "regional_revenue":6322.0,
    "other_revenue":5526.0,
    "non_operating_items":-1367.0
  }
]
财政年度是我要用来过滤数据的唯一标识符。如何过滤数据,例如财务年度为2,并将其他值放入数组中?

您可以在数组中使用该方法
filter
接受返回true或false(更准确地说,是truthy或false值)的回调。如果返回true,则该对象将包含在结果数组中

让输入=[
{
“财政年度”:1,
“主线收入”:18743.0,
“区域收入”:2914.0,
“其他收入”:3198.0,
“非经营性项目”:-1983.0
},
{
“财政年度”:2,
“主线收入”:20218.0,
“区域收入”:3131.0,
“其他收入”:3394.0,
“非经营性项目”:-3233.0
},
{
“财政年度”:3,
“主线收入”:30802.0,
“地区收入”:6322.0,
“其他收入”:5526.0,
“非经营性项目”:-1367.0
}
];
让输出=输入.filter((obj)=>obj.financial\u year!==2);

log(JSON.stringify(output,null,2))谷歌:MDN数组方法。你需要过滤器。可能是重复的。你试过什么吗?