javascript - React-Native - Object.assign children change -
sry if question still there searched , didn´t find solution. couldn´t hint out of developer.mozilla website objects.assign etc. described well.
the question:
how can change children of object? output described in following.
sample-code
var obj= {test: [{a: 2}, {b: 3}]}; var newchildren = [{a: 3}, {b: 5}, {c: 1}]; //i read obj key value following: var objkey = object.entries(obj)[0][0] //here want have code following result //my momentary regarding @webdeb var output = object.assign({}, {objkey: newchildren}) actual output: // {objkey: [{a: 3}, {b: 5}, {c: 1}]} wanted output: // {test: [{a: 3}, {b: 5}, {c: 1}]}
i have no other option code in other format "input" needed in way described. , need set objkey
variable, because have multiple keys in code wich have set multiple children. (doing filter stuff)
thanks help
br jonathan
first of all, don't use object
variable name..
ok, lets object obj
without modification of obj
var newobj = object.assign({}, obj, {test: newchildren})
or just, (modifies obj
)
obj.test = newchildren
is looking for?
Comments
Post a Comment