You are tasked with merging multiple source objects into a single target object, ensuring that properties from the latest source overwrite those in the target. Which operator would you use, and how would you apply it to accomplish this task?

  • Object.assign(target, ...sources);
  • target << sources;
  • target.merge(sources);
  • target.spread(...sources);
To merge multiple source objects into a single target object in JavaScript and ensure that properties from the latest source overwrite those in the target, you would use the Object.assign() method. The ...sources syntax spreads the source objects into the Object.assign() method, accomplishing the task efficiently. The other options are not valid for this operation.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *