javascript - How to round some values in an object array? -
array = [ {name:apples, price:3.99, tax:0.20}, {name:oranges, price:1.40, tax:0.15}, {name:bananas, price:0.99, tax:0.10}, ] how run tofixed() on "price" values (and not names, performance purposes) come this:
array = [ {name:apples, price:4, tax:0.20}, {name:oranges, price:1, tax:0.15}, {name:bananas, price:1, tax:0.10}, ] will have go through loop route?
just loop on array (btw: never use array variable name):
for (var i=0; i<arr.length; i++) arr[i].roundedprice = math.round(arr[i].price);
Comments
Post a Comment