我正在尝试选择比javascript函数更大的日期。我的函数返回空数组,我不知道我做错了
var arr = ["2018-01-24T17:43:03.000Z","2018-01-25T17:43:03.000Z","2018-01-
26T17:43:03.000Z","2018-01-27T17:43:03.000Z"]
var biggerThanElements = arr.filter(x=>{
x = new Date(x);
element = new Date("2018-01-23T00:00:00.000Z");
x > element
});
的console.log(biggerThanElements)
答案 0 :(得分:1)
您错过了更改为return x > element
var arr = ["2018-01-24T17:43:03.000Z","2018-01-25T17:43:03.000Z","2018-01-26T17:43:03.000Z","2018-01-27T17:43:03.000Z"]
var biggerThanElements = arr.filter(x=>{
x = new Date(x);
element = new Date("2018-01-23T00:00:00.000Z");
return x > element
});
console.log(biggerThanElements)
答案 1 :(得分:1)
您可以直接与ISO 8601日期/时间字符串进行比较。
//Public property with private get or writeonly
public int Prop { private get; set; }
//Readonyl property
public int Prop { get; private set; }

答案 2 :(得分:-1)
您的代码中存在一些问题:
return x > element
。2018-01-23
,所有日期都是"更大"。element
)。试试这个:
var arr = ["2018-01-24T17:43:03.000Z", "2018-01-25T17:43:03.000Z", "2018-01-26T17:43:03.000Z", "2018-01-27T17:43:03.000Z"]
var biggerThanElements = arr.filter(x => {
x = new Date(x);
var element = new Date("2018-01-25T00:00:00.000Z");
return x > element
});
console.log(biggerThanElements);