Created
July 31, 2018 10:59
-
-
Save felipem775/70394357462a393d7239a6ddc526ef6c to your computer and use it in GitHub Desktop.
Find the object whose property "X" has the greatest value in an array of objects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://stackoverflow.com/questions/4020796/finding-the-max-value-of-an-attribute-in-an-array-of-objects Andy Polhill | |
var n1 = { dateTime: new Date(), name: "n1"} | |
var n2 = { dateTime: new Date(), name: "n2"} | |
data = [n1, n2] | |
data.reduce(function (prev, current) { return (prev.dateTime > current.dateTime) ? prev : current }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment