lodash merge actually does what I exactly need.

https://blog.mariusschulz.com/2015/03/30/combining-settings-objects-with-lodash-assign-or-merge

// Defined within your component
var defaultSettings = {
    strictMode: true,
    formatting: {
        finalNewline: true,
        quotes: "double"
    }
};

// Provided by the developer using your component
var userSettings = {
    formatting: {
        quotes: "single"
    }
};

var assignedSettings = _.assign({}, defaultSettings, userSettings);

// {
//     strictMode: true,
//     formatting: {
//         quotes: "single"
//     }
// }

var mergedSettings = _.merge({}, defaultSettings, userSettings);

// {
//     strictMode: true,
//     formatting: {
//         finalNewline: true,
//         quotes: "single"
//     }
// }
Run code snippetEdit code snippet Hide Results Copy to answer Expand

Answer from Ata Mohammadi on Stack Overflow
๐ŸŒ
Mastering JS
masteringjs.io โ€บ tutorials โ€บ fundamentals โ€บ merge-two-objects
How to Merge Two Objects in JavaScript - Mastering JS
April 29, 2022 - To merge two objects in JavaScript, you can use the spread ... operator. The spread operator creates a new object with all the properties from the first and second object.
๐ŸŒ
JavaScript Tutorial
javascripttutorial.net โ€บ home โ€บ javascript merge objects
How to Merge Objects in JavaScript
March 29, 2020 - The following example uses the spread operator (...) to merge the person and job objects into the employee object: let person = { firstName: 'John', lastName: 'Doe', age: 25, ssn: '123-456-2356' }; let job = { jobTitle: 'JavaScript Developer', location: 'USA' }; let employee = { ...person, ...job }; console.log(employee); Copy ... { firstName: 'John', lastName: 'Doe', age: 25, ssn: '123-456-2356', jobTitle: 'JavaScript Developer', location: 'USA' } Copy
๐ŸŒ
David Walsh
davidwalsh.name โ€บ merge-objects
Merge Object Properties with the Spread Operator
March 1, 2017 - The ES6 spread operator feature in JavaScript allows for merging multiple object properties with a JavaScript library.
๐ŸŒ
Attacomsian
attacomsian.com โ€บ blog โ€บ javascript-merge-objects
How to merge two objects in JavaScript
August 26, 2022 - There are multiple ways to merge two objects in JavaScript. Use the Object.assign() method or spread operator (...) to perform a shallow merge of two objects.
Find elsewhere
๐ŸŒ
Medium
frontendinterviewquestions.medium.com โ€บ merge-two-objects-in-javascript-40f16605c13c
Merge two objects in JavaScript. Source:- Merge two objects inโ€ฆ | by Pravin M | Medium
April 15, 2024 - The spread operator (โ€ฆ) is a convenient way to merge objects in JavaScript. It allows us to expand the properties of an object into another object. Hereโ€™s how you can merge two objects using the spread operator:
๐ŸŒ
YouTube
youtube.com โ€บ watch
Javascript Tutorial to Merge Properties of Multiple Objects Using Object.assign & Spread Operator - YouTube
Buy the full source code of application here:https://procodestore.com/index.php/product/javascript-tutorial-to-merge-properties-of-multiple-objects-using-obj...
Published: October 17, 2021
๐ŸŒ
SitePoint
sitepoint.com โ€บ blog โ€บ javascript โ€บ how to merge objects in javascript
How to Merge Objects in JavaScript โ€” SitePoint
November 5, 2024 - Learn how to merge any object in JavaScript with the spread ( ... ) operator, Object.assign() method, and JSON stringify and parse methods.
๐ŸŒ
YouTube
youtube.com โ€บ watch
Merge two objects with spread operator in javaScript - YouTube
How to Merge Objects in JavaScript with the Spread OperatorIn this video, you'll learn how to merge objects in JavaScript using the spread operator (...). Th...
Published: February 19, 2025
Views: 1
๐ŸŒ
30 Seconds of Code
30secondsofcode.org โ€บ home โ€บ javascript โ€บ object โ€บ merge objects
Merge two or more JavaScript objects - 30 seconds of code
March 20, 2024 - In order to do so, we can use Object.keys() to get the keys of both objects, create a Set from them, and use the spread operator (...) to create an array of all the unique keys. We can then use Array.prototype.reduce() to add each unique key ...
๐ŸŒ
Medium
medium.com โ€บ @lehetar749 โ€บ merge-objects-and-delete-initial-keys-with-javascript-spread-syntax-6496d35f9a16
Merge Objects and Delete Initial Keys with JavaScript Spread Syntax | by Lehetar zask | Medium
October 25, 2024 - By placing the spread operator before each object you want to merge, you can combine their properties into a new object. The order in which you list the objects matters, as later objects will overwrite properties from earlier ones. javascript ...
๐ŸŒ
Byby
byby.dev โ€บ js-merge-objects
5 ways to merge two objects in JavaScript
If there are properties with the same name in the source objects, the spread operator will overwrite the values in the new object with the latest source objectโ€™s values. let obj1 = { name: "Alice", age: 25 }; let obj2 = { name: "Bob", city: "New York" }; let obj3 = { ...obj1, ...obj2 }; console.log(obj3); // { name: "Bob", age: 25, city: "New York" } ... This is a way to copy all enumerable own properties from one or more source objects to a target object.
๐ŸŒ
Stack Abuse
stackabuse.com โ€บ merge-properties-of-two-objects-dynamically-in-javascript
Merge Properties of Two Objects Dynamically in JavaScript
October 4, 2023 - In this tutorial, we've taken a look at how to merge two objects in JavaScript. We've explored the spread operator (...) and the Object.assign() method, which both perform a shallow merge of two or more objects, into a new one, without affecting the constituent parts.
๐ŸŒ
YouTube
youtube.com โ€บ shorts โ€บ NT0hWMRwPMQ
Merge Multiple Objects Using Spread Operator | Spread Operator JavaScript | #Shorts | SimpliCode - YouTube
You may have a need to merge two objects together and create a better informative object to work with. JavaScript allows its users to merge objects in two wa...
Published: May 21, 2022
๐ŸŒ
egghead.io
egghead.io โ€บ lessons โ€บ javascript-merge-objects-with-javascript-s-spread-operator
Merge Objects with JavaScript's Spread Operator | egghead.io
Using the spread operator you can merge objects. This example uses two objects, but the syntax is the same for more. Note that duplicate keys will be ov...
Published: July 16, 2019
๐ŸŒ
Vultr Docs
docs.vultr.com โ€บ javascript โ€บ examples โ€บ merge-property-of-two-objects
JavaScript Program to Merge Property of Two Objects | Vultr Docs
December 17, 2024 - Use the spread operator within a new object declaration to ensure the original objects remain unchanged. ... This technique creates a new object entirely, ensuring that neither object1 nor object2 is modified during the process.