1const users = [
2 { name: "Alex", age: 25 },
3 { name: "John", age: 32 },
4];
5
6const newUsers = users.map((user) => ({
7 ...user,
8 age: user.age + 5, // just for example
9}));
10
11// newUsers = [
12// {name:"Alex" , age:30},
13// {name:"John , age:37}
14// ]
1//Initailize array of objects.
2let myArray = [
3 {id: 0, name: "Jhon"},
4 {id: 1, name: "Sara"},
5 {id: 2, name: "Domnic"},
6 {id: 3, name: "Bravo"}
7],
8
9//Find index of specific object using findIndex method.
10objIndex = myArray.findIndex((obj => obj.id == 1));
11
12//Log object to Console.
13console.log("Before update: ", myArray[objIndex])
14
15//Update object's name property.
16myArray[objIndex].name = "Laila"
17
18//Log object to console again.
19console.log("After update: ", myArray[objIndex])
1const arrayOfObj = [{
2 key1: 'value1',
3 key2: 'value2'
4}, {
5 key1: 'value1',
6 key2: 'value2'
7}];
8const newArrayOfObj = arrayOfObj.map(({
9 key1: stroke,
10 ...rest
11}) => ({
12 stroke,
13 ...rest
14}));
15
16console.log(newArrayOfObj);