Ranjith M Ranjith M - 1 year ago 142
AngularJS Question

how to get the min and max value from json in angular js

i want to get the maximum and minimum value from a json in angular js
my json:



"name": "ranjith",
"age": 22
"name": "rahul",
"age": 20
"name": "jinesh",
"age": 25
"name": "vishnu",
"age": 24



and my controller:-

var app = angular.module('myApp', ['']);
app.controller('myCtrl', function($scope, data) {

$scope.data = data.data;


i want to get the minimum and maximum value from the array and store it in the Variables min and max

Shb Shb
Answer Source

You can simply use

$scope.min = Math.min.apply(Math,$scope.data.map(function(item){return item.age;}));

$scope.max = Math.max.apply(Math,$scope.data.map(function(item){return item.age;}));
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download