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 :: setting timeout in javascript 
Javascript :: regex expression to match domain name 
Javascript :: javascript get specific timezone 
Javascript :: jquery body remove class 
Javascript :: plotly in react 
Javascript :: on load page javascript 
Javascript :: react append classname 
Javascript :: js check if array of dictionaries contain 
Javascript :: get timezone name from date javascript 
Javascript :: update object in array if id exists else append javascript 
Javascript :: comparing two arrays in javascript returning differences 
Javascript :: tribonacci sequence javascript 
Javascript :: angular get element by classname 
Javascript :: js remove first element from array 
Javascript :: remove hostname from url javascript 
Javascript :: ts node cannot use import statement outside a module 
Javascript :: how to get the size of the window in javascript 
Javascript :: how to get output of console.log in a file in javascript 
Javascript :: mongoose update push 
Javascript :: hide a div in jquery 
Javascript :: how to compare objets in an array 
Javascript :: express req get json 
Javascript :: form submit event get button 
Javascript :: javascript check if string contains special characters 
Javascript :: How to do a timer angular 
Javascript :: space in string using if in jquery 
Javascript :: what is functional composition 
Javascript :: how to remove child element in jquery 
Javascript :: webpack error cannot find module 
Javascript :: types of loops in javascript 
ADD CONTENT
Topic
Content
Source link
Name
8+1 =