我想从角js中的json获得最大值和最小值
我的json:
我的json:
{ "data":[ { "name": "ranjith","age": 22 },{ "name": "rahul","age": 20 },{ "name": "jinesh","age": 25 },{ "name": "vishnu","age": 24 } ] }
和我的控制器: –
var app = angular.module('myApp',['']); app.controller('myCtrl',function($scope,data) { $scope.data = data.data; $scope.min=""; $scope.max=""; }; });
我想从数组中获取最小值和最大值,并将其存储在变量min和max中
你可以简单地使用
原文链接:/angularjs/141432.html$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;}));