Clone and edit this document
Runkit
Runkit
home page
user forum
new notebook
clone notebook
download notebook
support & documentation
log in
sign up
new notebook
help & feedback
clone this notebook
download this notebook
Sign In
Sign Up
RunKit + npm: deepmerge
node v15.14.0
version:
master
endpoint
share
tweet
const deepmerge = require("deepmerge"); const oneVariable = { "default": { "init": { "body": { "hello": "ads", "hi": "2", "password1": "s", }, }, }, }; const twoVariable = { "default": { "init": { "body": { "hello": "ads", "password1": "s", }, }, }, }; const customMerge = () => (A, B) => { const mergedResult = deepmerge(A, B, { customMerge }); for (const keyA of Object.keys(A)) { if (!Object.prototype.hasOwnProperty.call(B, keyA)) { delete mergedResult[keyA]; } } return mergedResult; }; const result = customMerge()( oneVariable, twoVariable ); console.log(result);
Created from: https://npm.runkit.com/deepmerge
Loading…
no comments
sign in
to comment