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 :: install nodemon 
Javascript :: js populate an empty array of zeros 
Javascript :: get combinations of two js 
Javascript :: can i pass data with usenavigate react router 
Javascript :: jquery window trigger resize 
Javascript :: generate random id javascript 
Javascript :: jsp include html 
Javascript :: package.json set environment variables 
Javascript :: fetching iframe content JS 
Javascript :: angular show time ago 
Javascript :: safeareaview not working on android react native 
Javascript :: how to disable back js 
Javascript :: javascript string to float 
Javascript :: laravel array to js 
Javascript :: dayofweek javascript 
Javascript :: replace class js 
Javascript :: convert string time to time in javascript 
Javascript :: vaidate youtube url 
Javascript :: webpack react proxy not working 
Javascript :: creating a class in angular 
Javascript :: react toastify does not have design 
Javascript :: you should not use switch outside a router react 
Javascript :: search in string array javascript 
Javascript :: link on click jquery 
Javascript :: export html table data to excel using javascript 
Javascript :: create file if not exists nodejs 
Javascript :: last element in array 
Javascript :: jquery remove option from select 
Javascript :: move element jquery 
Javascript :: example of pre increment in js 
ADD CONTENT
Topic
Content
Source link
Name
9+1 =