So I want to modify the name of some objects by replacing certain characters with others, in this case (as an example) the letter "g" with "k". Now I want to have back the same array of objects with just one value altered of all objects, the name. But instead of getting back the object array, I only get back all altered values (object.name). I thought with .map()
, I can transform an object array and get it back just with the function applied to all objects.
var students = [
{ "number": 4251, "name": "Melissa", "surname": "Giron" },
{ "number": 4321, "name": "Gisele", "surname": "Johnsen" }
]
So this is my example array where I want to change the letter "e" to "z" in all names.
function changeLetterInName(students) {
return students.map(x => x.name.replace("e", "z"));
}
What I actually want:
[
{ number: 4251, name: 'Mzlissa', surname: 'Giron' },
{ number: 4321, name: 'Giszlz', surname: 'Johnsen' }
]
What I get:
['Mzlissa', 'Giszlz']