Underscore.JS - min method
Syntax
_.min(list, [iteratee], [context])
min method gets the minimum value of the list. In case of iteratee method provided than it is used to compare values. It ignores the non-numerical values.
Example
var _ = require('underscore');
var list = [{name: 'Sam', age: 10}, {name: 'Joe', age: 12}, {name: 'Rob', age: 15}]
//Example 1. invoke min method to get youngest student
var result = _.min(list, function(list){ return list.age});
console.log(result);
list = [1, 4, 6, 3, 7, 9]
//Example 2. invoke min method to get maximum number
result = _.min(list)
console.log(result)
Save the above program in tester.js. Run the following command to execute this program.
Command
\>node tester.js
Output
{ name: 'Sam', age: 10 }
1
underscorejs_processing_collection.htm
Advertisements