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

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -