Changing the Name of a Key in JavaScript: A Guide

The original object’s properties can be modified by either deleting the old ones and adding new, or by extending the prototype of Object. The solution to this problem involves two parts: firstly, determining if there is a specific order and whether unknown properties should be omitted using Underscore, ES5/loop, ES5/reduce, or ES6. Secondly, an array of small objects is created, each with a single key-value pair, utilizing the ES6 “computed property name” feature, and then merged together using the ES6 “spread” operator.


You can do it using map like this:

let Options = [{Code: 1, Label: 'abc'}, {Code: 2, Label: 'xyz'}, {Code: 3, Label: 'fgh'}];
const res = => {
  elem.value = elem.Code;
  delete elem.Code;
  return elem;

Frequently Asked Questions