Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

json rename key

// Rename a key in JSON by moving it to a new key and deleting the old one

data = { oldName: 1, other: 2 }

data.newName = data.oldName
delete data.oldName

// new data: { other: 2, newName: 1 }
Comment

rename json key object

const renameKey = (object, key, newKey) => {

  const clonedObj = clone(object);

  const targetKey = clonedObj[key];



  delete clonedObj[key];

  clonedObj[newKey] = targetKey;

  return clonedObj;

};
Comment

rename json key object

const clone = (obj) => Object.assign({}, obj);
Comment

PREVIOUS NEXT
Code Example
Javascript :: d3.json() function 
Javascript :: js click element 
Javascript :: jquery change select option text 
Javascript :: examples of toastr in jquery 
Javascript :: define array with custom index javascript 
Javascript :: materialize for react 
Javascript :: js select element by css selector 
Javascript :: javascript remove character from string 
Javascript :: how to loop through date range in javascript 
Javascript :: express serve home page 
Javascript :: javascript current date time 
Javascript :: how to make a rectangle in javascript 
Javascript :: download canvas js 
Javascript :: fs.writefilesync in nodejs 
Javascript :: remove single item from array in angular 
Javascript :: js datetime local 
Javascript :: flutter access json object inside object 
Javascript :: zoom out browser javascript 
Javascript :: settimeout inside loop 
Javascript :: string split javascript 
Javascript :: nodejs wait event loop to finish 
Javascript :: getting href value in jquery 
Javascript :: js add element to front of array 
Javascript :: array remove index from array 
Javascript :: javascript truncate array 
Javascript :: jest match object properties 
Javascript :: javascript date pipe central timezone example 
Javascript :: js insert item into array 
Javascript :: node js return json 
Javascript :: Send Email using AWS SES and Lambda 
ADD CONTENT
Topic
Content
Source link
Name
3+8 =