Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
67
rated 0 times [  68] [ 1]  / answers: 1 / hits: 29518  / 9 Years ago, mon, june 8, 2015, 12:00:00

I have sample data as:



data = [
[1, 622, 782, 783, 2015-04-21],
[2, 622, 782, 783, 2015-04-21],
[3, 622, 782, 783, 2015-04-22],
[4, 622, 782, 783, 2015-04-23],
[5, 622, 782, 783, 2015-04-24],
[6, 622, 782, 783, 2015-04-28],
[7, 622, 782, 783, 2015-04-28],
[8, 622, 782, 783, 2015-04-29],
[9, 622, 782, 783, 2015-05-04],
[10, 622, 782, 783, 2015-05-05]
]


How can I get the max date value and min date value from the above data? The data may be not in sorted order.


More From » jquery

 Answers
15

1) Use map to extract the dates:



var dates = data.map(function(x) { return new Date(x[4]); })


2) Use Math.max / Math.min to get the highest / lowest dates:



var latest = new Date(Math.max.apply(null,dates));
var earliest = new Date(Math.min.apply(null,dates));

[#66291] Friday, June 5, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
lamarmaximiliand

Total Points: 388
Total Questions: 104
Total Answers: 104

Location: Oman
Member since Fri, Dec 23, 2022
1 Year ago
;