I am trying to code this in ES6. Below is what I am trying to achieve. Let\'s say I have an array of objects called schools
.
let schools = [
{na
let schools = [{
name: 'YorkTown',
country: 'Spain'
},
{
name: 'Stanford',
country: 'USA'
},
{
name: 'Gymnasium Achern',
country: 'Germany'
}
];
let updatedSchools = [{
name: 'New Gen',
country: 'Spain'
},
{
name: 'Stanford',
country: 'USA'
},
{
name: 'Gymnasium Achern',
country: 'Germany'
}
];
const editSchoolName = ((schools, oldName, name) =>{
schools.map(item => {
if (item.name === oldName) {
item.name = name;
return item.name;
} else {
return item;
}
});
console.log(schools);
});
editSchoolName(schools, 'YorkTown', "New Gen");