Two identical JavaScript dates aren't equal

前端 未结 3 513

When I create two identical JavaScript Date objects and then compare them, it appears that they are not equal. How to I test if two JavaScript dates have the sa

3条回答
  •  情深已故
    2020-12-03 10:46

    I compare many kinds of values in a for loop, so I wasn't able to evaluate them by substracting, instead I coverted values to string before comparing

    var a = [string1, date1, number1]
    var b = [string2, date2, number2]
    for (var i in a){
      if(a.toString() == b.toString()){
        // some code here
      }
    }
    

提交回复
热议问题