My response object containing startTime
, I want to compare all the startTimes and get the latest time to display on timeline.
How can I find the latest Date and time using moment.js
Response I am getting –
[{
name:"abc",
type:"CALL",
startTime:"2021-10-13T07:16:55Z",
},{
name:"def",
type:"CALL",
startTime:"2021-10-13T07:18:57Z",
},{
name:"ghi",
type:"CALL",
startTime:"2021-10-15T07:17:05Z",
},{
name:"jkl",
type:"CALL",
startTime:"2021-11-03T12:07:52Z",
}]
My code –
response.forEach((d)=>{
if(d.type == 'CALL'){
console.log("latest start time ",d);
$scope.view(d); //need to pass the obj of latest startTime only
$scope.$apply();
}else{
//Something else
}
})
How can I do this using JavaScript or moment?