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

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -