i want to get the maximum and minimum value from a json in angular js my json:
{
"data":[
{
"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;
$scope.min="";
$scope.max="";
};
});
i want to get the minimum and maximum value from the array and store it in the Variables min and max
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;}));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With