Home > Mobile >  I'm trying to check dates between an array, but returns me a empty array
I'm trying to check dates between an array, but returns me a empty array

Time:12-24

<button
            onClick={() =>
              console.log(
                data.filter(
                  (element: apiData) =>
                    new Date(element.dataemissao) >= allDatesRange[0] &&
                    new Date(element.dataemissao) <= allDatesRange[length - 1],
                ),
              )
            }
          >
            data filteres
          </button>

It's working when I try get just dates that are bigger than the first value of allDatesRange array.

CodePudding user response:

Try this.

<button
        onClick={() =>
          console.log(
            data.filter(
              (element: apiData) =>
                new Date(element.dataemissao) >= allDatesRange[0] &&
                new Date(element.dataemissao) <= allDatesRange[allDatesRange.length - 1],
            ),
          )
        }
      >
        data filteres
      </button>
  • Related