Using $ .each
var items = [{ "id": 2 }, { "id": 1 }, { "id": 3 }]; var maxId = Number.MIN_VALUE; $.each(items, function (index, item) { maxId = Math.max(maxId, item.id); });
Using ES5 for Each
var maxId = Number.MIN_VALUE; items.forEach(function (item) { maxId = Math.max(maxId, item.id) });
Using ES5 reduces
var maxId = items.reduce(function (maxId, item) { return Math.max(maxId, item.id) }, Number.MIN_VALUE);
Using Underscore.js
Underscore.js has max , which also works in older browsers:
var maxId = _.max(items, function (item) { return item.id }).id;
source share