Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

change object key name javascript es6

const countries = [
    {"id": 1, "name": "Afghanistan"},
    {"id": 2, "name": "Albania"},
    {"id": 3, "name": "Algeria"},
    {"id": 4, "name": "American Samoa"}
];
const transformed = countries.map(({ id, name }) => ({ label: id, value: name }));
console.log(transformed);
Comment

rename object keys javascript

function renameKeys(obj, newKeys) {
  const keyValues = Object.keys(obj).map(key => {
    const newKey = newKeys[key] || key;
    return { [newKey]: obj[key] };
  });
  return Object.assign({}, ...keyValues);
}
Comment

change object key name javascript es6

const countries = [
    {"id": 1, "name": "Afghanistan"},
    {"id": 2, "name": "Albania"},
    {"id": 3, "name": "Algeria"},
    {"id": 4, "name": "American Samoa"}
];
const transformed = countries.map(({ id: label, name: value }) => ({ label, value }));
console.log(transformed);
Comment

PREVIOUS NEXT
Code Example
Javascript :: disable radio button javascript 
Javascript :: get json by id 
Javascript :: object to json javascript 
Javascript :: jsx if block 
Javascript :: check if function exists javascript 
Javascript :: es6 compare two arrays 
Javascript :: change js to json 
Javascript :: regex to check the phone number javascript 
Javascript :: How to include JSPs file from another folder 
Javascript :: onclick string 
Javascript :: angular delete from array by name 
Javascript :: python get json content from file 
Javascript :: how to create uuid in javascript 
Javascript :: javascript escape quote method 
Javascript :: error duplicate resources react native 
Javascript :: splice last element from array javascript 
Javascript :: react check if focused 
Javascript :: redirect script javascript 
Javascript :: js display only date 
Javascript :: javascript MAX INT and MIN INT 
Javascript :: URL scheme "localhost" is not supported. 
Javascript :: li key attribute 
Javascript :: jquery get selected text from multiselect 
Javascript :: jquery merge objects 
Javascript :: if button is pressed js 
Javascript :: ERR_REQUIRE_ESM 
Javascript :: discord js send dm to user 
Javascript :: class constructor 
Javascript :: javascript remove a specific item from an array 
Javascript :: react useeffect async 
ADD CONTENT
Topic
Content
Source link
Name
1+1 =