Return the last date of the Array

0

Hello, I have a code where I am looking for a list of dates.

    for(var i = 0; i < data.list.length; i++){
      if(Date.parse(data.list[i].date) >= dateA){

            console.log(data.list[i].date)


      }          
  }

I would like to know if there is a possibility to return only the last date of the array.

    
asked by anonymous 26.03.2018 / 20:18

1 answer

0

Just get the size of the array, its size is the index of your last value

var t = data.list.length;

console.log(data.list[t].date);

I think this resolves

But if you want to get the last date and not the last index, you can do a sort in the array and then get the last index

array.sort();
    
26.03.2018 / 20:22