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
Post a Comment