79734698

Date: 2025-08-13 20:09:02
Score: 0.5
Natty:
Report link

Simple ~1 liner to do this with Object.entries and Object.fromEntries as well.

const renameKey = (obj, oldKey, newKey) => Object.fromEntries(Object.entries(obj).map(([key, value]) => [
  key === oldKey ? newKey : key, value
]));
Reasons:
  • Low length (0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Dennis