Skip to content

Instantly share code, notes, and snippets.

View myagizmaktav's full-sized avatar

Mehmet Yağız Maktav myagizmaktav

View GitHub Profile
@myagizmaktav
myagizmaktav / deep-merge.js
Created November 2, 2022 20:08 — forked from ahtcx/deep-merge.js
Deep-Merge JavaScript objects with ES6
// ⚠ IMPORTANT: this is old and doesn't work for many different edge cases but I'll keep it as-is for any of you want it
// ⚠ IMPORTANT: you can find more robust versions in the comments or use a library implementation such as lodash's `merge`
// Merge a `source` object to a `target` recursively
const merge = (target, source) => {
// Iterate through `source` properties and if an `Object` set property to merge of `target` and `source` properties
for (const key of Object.keys(source)) {
if (source[key] instanceof Object) Object.assign(source[key], merge(target[key], source[key]))
}