function replaceKey(key, newKey, object) {

  // (1) iterate object keys
  Object.entries(object).forEach(entry => {

    if (isArray[ entry[ 1 ]]) {

      // (2.1) recurse
      entry[ 1 ].forEach(item => replaceKey(key, newKey, item));
    }

    if (isObject(entry[ 1 ])) {

      // (2.2) recurse
      replaceKey(key, newKey, entry[ 1 ]);
    }

    if (entry[ 0 ] === key) {

      // (3) replace key
      object[ newKey ] = entry[ 1 ];

      delete object[ key ];
    }
  });
}
/**
 * Replace all occurrences of key in object.
 *
 * @param {*} key
 * @param {*} newKey
 * @param {Object} object
 */
Replace all occurrences of key in object.


Replace all occurrences of key in object .
function replaceKey(key, newKey, object) {
  Object.entries(object).forEach(entry => {
    if (isArray[ entry[ 1 ]]) {
      entry[ 1 ].forEach(item => replaceKey(key, newKey, item));
    }
    if (isObject(entry[ 1 ])) {
      replaceKey(key, newKey, entry[ 1 ]);
    }
    if (entry[ 0 ] === key) {
      object[ newKey ] = entry[ 1 ];
      delete object[ key ];
    }
  });
}
function replaceKey ( key , newKey , object ) { Object . entries ( object ) . forEach ( entry => { if ( isArray [ entry [ 1 ] ] ) { entry [ 1 ] . forEach ( item => replaceKey ( key , newKey , item ) ) ; } if ( isObject ( entry [ 1 ] ) ) { replaceKey ( key , newKey , entry [ 1 ] ) ; } if ( entry [ 0 ] === key ) { object [ newKey ] = entry [ 1 ] ; delete object [ key ] ; } } ) ; }
Replace all occurrences of key in object.
Replace all occurrences of key in object .
// (1) iterate object keys
 // (2.1) recurse
 // (2.2) recurse
 // (3) replace key
