I have this array:
["2018-01", "2018-02", "2018-03", "2018-04", "2018-05", "2018-06", "2018-07", "2018-08"]
And this code is suposed to seak if a date is between the start/end but is not working:
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) } }); }); The result is a very long list like this:
But if you try this like concept:
var isbetween = moment('2015-05-15').isBetween('2015-05-01', '2015-05-31'); console.log("valor de isbetwen",isbetween ) Is working.
What is wrong with the code?

if ( tonto = true ){you meanif ( tonto == true ){orif ( tonto === true ){... sinceif ( tonto = true ){is ALWAYS true as you assigned it to be true (= is assignment, not equality check)