javascript - How to add object property in map -


i tried add property in map loop seems updated on copy not object itself.

my_array.map(function(d){   d.size = do_seomthing }); 

you have reassign my_array

my_array = my_array.map(function(d){   d.size = [somevalue];    return d; // per comment }); 

another way directly rewrite array using array initial value (see mdn link more on that):

my_array.map(function(d, i){   this[i].d.size = [somevalue]; }, my_array); 

from mdn:

the map() method creates new array results of calling provided function on every element in array.


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 -