Finding the max value of a property in an array of objects

To find the maximum y value of the objects in array:

Math.max.apply(Math, { return o.y; }))

or in more modern JavaScript:

Math.max( => o.y))


This method is not advisable, it is better to use reduce. With a large array, Math.max will be called with a large number of arguments, which can cause stack overflow.

Leave a Comment