Update deep objects and get notified about changes

Usage no npm install needed!

<script type="module">
  import objectDiffer from 'https://cdn.skypack.dev/object-differ';



Node module to update deep objects and get notified about changes


$ npm install object-differ


var differ = require('object-differ');

var obj = {
    'This': 'is',
    'a': {
        'test': 'object',
        'demonstrating': 'the'
    'functionality': ['of', 'object-differ']

var update = {
    'a': {
        'test': 'that isn\'t'

// The function will be called whenever a value changes
differ(obj, update, function(key, value, old, path) {
    console.log('Changed', key, 'from', old, 'to', value);
    // OUTPUT: Changed test from object to that isn't


differ(obj, update, callback, notifyObjects, strict)
  • obj: Target object you want to update (object)
  • update: Object containing what you want to replace (object)
  • callback: Called whenever a key in obj differs from the matching key in update (function)
  • notifyObjects: set to true to get notified about objects (e.g. parents) changing (true, false)
  • strict: If update doesn't contain a key, delete it from obj (true, false)