renameKeys in javascript

PHOTO EMBED

Wed May 06 2020 11:46:54 GMT+0000 (Coordinated Universal Time)

Saved by @Glowing #javascript

const renameKeys = (keysMap, obj) =>
  Object.keys(obj).reduce(
    (acc, key) => ({
      ...acc,
      ...{ [keysMap[key] || key]: obj[key] }
    }),
    {}
  );
EXAMPLES
const obj = { name: 'Bobo', job: 'Front-End Master', shoeSize: 100 };
renameKeys({ name: 'firstName', job: 'passion' }, obj); // { firstName: 'Bobo', passion: 'Front-End Master', shoeSize: 100 }
                             
                                
content_copyCOPY

https://www.30secondsofcode.org/js/s/rename-keys/