我有这个数组:
[“ 2018-01”,“ 2018-02”,“ 2018-03”,“ 2018-04”,“ 2018-05”,“ 2018-06”,“ 2018-07”,“ 2018-08” “]
如果日期在开始/结束之间但不起作用,则此代码将被塞住:
array.forEach(function(item){
//console.log(item)
var a = moment(item);
var start = a.format('YYYY-MM-DD')
var b = a.add(30, 'days');
var end = b.format('YYYY-MM-DD')
console.log("procesing search between date : ",start , " and last date: ", end)
letrado.forEach((value, key) => {
//console.log("1-key =>", key, "1-value =>", value.compra_fecha_oper);
let polo = moment(value.compra_fecha_oper).format('YYYY-MM-DD')
var tonto = moment(polo).isBetween(String(start), String(end) ); // true
if ( tonto = true ){
console.log(key, " Value Date: ",value.compra_fecha_oper ,"Has result: ", tonto)
}
});
});
结果是一个很长的列表,像这样:
但是,如果您尝试这样的概念:
var isbetween = moment('2015-05-15').isBetween('2015-05-01', '2015-05-31');
console.log("valor de isbetwen",isbetween )
正在工作。
代码有什么问题?
答案 0 :(得分:1)
此行是问题,
if ( tonto = true ){
这应该等于
的三倍if ( tonto === true ){
/* or simply */
if ( tonto ){