0

I want to convert the following assignment to something that uses object spread instead:

bData.steps[bStepKey].params= cData[cKey]

I have tried below with no luck.

bData= {...bData, steps:{ ...bData.steps[bStepKey], params: cData[cKey]}}

1 Answer 1

0

You don't need the spread operator, but if you really wanted to use it:

bData = { ...bData, steps: { ...bData.steps, [bstepKey]: { ...steps[bstepKey], params: cData[cKey] }}};

Although it's not useful at all in this situation as you don't need to spread anything - your initial approach is much better:

bData.steps[bStepKey].params= cData[cKey]
Sign up to request clarification or add additional context in comments.

5 Comments

Compiler says cannot find name steps
Thank you I got it to work because of you. Didn’t know I had to put the index in a bracket.
By the way, JavaScript is interpreted not compiled.
Thanks. The reason why I’m using spread is because of this stackoverflow.com/questions/44288164/…
Typescript is compiled though :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.