Underscore.js Collections: Min

by tylerbrownhenry

HTML

<script src="http://documentcloud.github.com/underscore/underscore-min.js"></script>
<a target="parent" href="http://underscorejs.org/#min">Learn More</a>

JavaScript

var movies = [{title:'Pulp Fiction',star:'Many',year:'1995'},{title:'Mean Girls',star:'Lindsey',year:'2000'}];

//Finds the lowest number in a set of values, based off a given key
var testMax = _.min(movies, function(movie){ return movie.year;});

console.log(testMax);
//Object {title: "Pulp Fiction", star: "Many", year: "1995"}