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.
Loading...
Related Quiz
- How can you send JSON data as a response using the http module in Node.js?
- How can you set up ESLint to lint TypeScript files in a project?
- What is a closure in JavaScript?
- What strategies can be employed to optimize aggregation queries in NoSQL databases like MongoDB?
- How can you implement a custom writable stream in Node.js?