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

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -