Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

change value of key in array of objects javascript

const users = [
  { name: "Alex", age: 25 },
  { name: "John", age: 32 },
];

const newUsers = users.map((user) => ({
  ...user,
  age: user.age + 5, // just for example
}));

// newUsers = [
// {name:"Alex" , age:30},
// {name:"John , age:37}
// ]
Comment

change key in array of objects javascript

let arrayObj = [{key1:'value1', key2:'value2'},{key1:'value1', key2:'value2'}];

arrayObj = arrayObj.map(item => {
      return {
        stroke: item.key1,
        key2: item.key2
      };
    });
Comment

change key name in array of objects javascript

const arrayOfObj = [{
  key1: 'value1',
  key2: 'value2'
}, {
  key1: 'value1',
  key2: 'value2'
}];
const newArrayOfObj = arrayOfObj.map(({
  key1: stroke,
  ...rest
}) => ({
  stroke,
  ...rest
}));

console.log(newArrayOfObj);
Comment

PREVIOUS NEXT
Code Example
Javascript :: string remove accents 
Javascript :: jquery vdn 
Javascript :: isset js 
Javascript :: javascript skip default parameter 
Javascript :: javascript convert string to number or integer 
Javascript :: back button next js 
Javascript :: moment use in angular 
Javascript :: react open url with button 
Javascript :: clean react app 
Javascript :: Angular Unit Testing: Observable not returning results 
Javascript :: Truncate a string-Javascript 
Javascript :: check if array has same values javascript 
Javascript :: js delete all array items 
Javascript :: js transform 
Javascript :: angular access current scope from console 
Javascript :: js skip to next iteration 
Javascript :: ... array operator javascript 
Javascript :: jquery datatable iterate all rows 
Javascript :: javascript array random selector 
Javascript :: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project electronicbookshop: Compilation failure 
Javascript :: redirect with react router v6 
Javascript :: $(document).ready, window.onload 
Javascript :: javascript dynamicly include another js file 
Javascript :: get largest number in array javascript 
Javascript :: set cursor type javascript 
Javascript :: javascript filter unique 
Javascript :: how to convert array to uppercase in javascript 
Javascript :: ajax datatable reload paging retained 
Javascript :: how to get user input in javascript 
Javascript :: word count javascript 
ADD CONTENT
Topic
Content
Source link
Name
4+7 =