Lodash allows computing the maximum and minimum values of an array.
Learn Lodash JS at Lodash JS Tutorial with Examples.
Learn Lodash JS at Lodash JS Tutorial with Examples.
Lodash _.min and _.max() Methods Example
<!DOCTYPE html>
<html>
<head>
<title>Lodash Tutorial</title>
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.11/lodash.min.js"></script>
<script type="text/javascript">
const vals = [-3, 4, 0, 12, 43, 9, -12];
var min = _.min(vals);
console.log(min);
var max = _.max(vals);
console.log(max);
max = _.max(_.range(5, 25));
console.log(max);
const obs = [{n: 12}, {n: -4}, {n: 4}, {n: -11}];
min = _.minBy(obs, 'n');
console.log(min);
max = _.maxBy(obs, 'n');
console.log(max);
</script>
</head>
<body></body>
</html>
Output:
-12
43
24
{ n: -11 }
{ n: 12 }
Comments
Post a Comment