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

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -