Javascript get values inside an object and add them together? -
i'm wondering if it's possible loop through set objects in angular , perform maths on retrieved values.
i have object ($scope.basketitems
) , i'd know if it's possible (and if how) loop through each item inside $scope.basketitems
, extract each price
, add price
's create total figure?
i use lodash or underscore, this:
$scope.basketitems = [ {name: 'bob', price: 50}, {name: 'tim', price: 25}, {name: 'sarah', price: 25} ]; $scope.sum = 0; _.foreach( $scope.basketitems, function(item) { $scope.sum += item.price; });
sum = 100;
Comments
Post a Comment