JSFiddle - React, Tailwind, and code Playground
JavaScript
function min(collection, property) {
if (collection.length == 0) {
return null;
}
var minIndex = 0;
var minValue = collection[0][property];
for (var i = 1; i < collection.length; ++i) {
if (minValue > collection[i][property]) {
minValue = collection[i][property];
minIndex = i;
}
}
return collection[minIndex];
}
var items = [
{ name: "John", age: 20 }, { name: "Mary", age: 18 }
];
alert(min(items, 'age').name);