【发布时间】:2019-09-13 09:50:15
【问题描述】:
我正在尝试根据日期获取失败详细信息。 为此,我正在应用 array.filter 但它返回的是空数组。
下面是我的数组:
value:[{
"Date": "02/04/2019",
"Total": "1000",
"Success": "850",
"Failure": "150",
"FailureDeatils": [{
"Reason": "Reason1",
"Count": 2
},
{
"Reason": "Reason2",
"Count": 6
}
]
}, {
"Date": "03/04/2019",
"Total": "800",
"Success": "750",
"Failure": "150",
"FailureDeatils": [{
"Reason": "Reason1",
"Count": 3
}, {
"Reason": "Reason2",
"Count": 1
}]
}]
如果我将日期设为 02/04/2019,它应该返回以下内容:
{
"FailureDeatils": [{
"Reason": "Reason1",
"Count": 2
},
{
"Reason": "Reason2",
"Count": 6
}
]
}
我正在使用下面的 array.filter 方法:
var filtered = value.filter(isPresent);
function isPresent(value) {
return value == 02/04/2019;
}
这是返回空数组。
谁能帮我弄清楚我哪里出错了?
【问题讨论】:
-
return value.Date == "02/04/2019";也许? -
什么是isPresent?请分享您使用 isPresent 申请的条件
-
is Present 只不过是下面写的函数
-
好的,我已经根据您的代码添加了答案。在代码中实现之前,您也可以在浏览器控制台上对其进行测试。
-
如果对您有用,请为该问题投票。谢谢!
标签: javascript arrays date object filtering