As a novice student, I am currently working on improving my understanding of .map()
. My goal is to create a callback function that can generate a list of full names by assigning last names from the lastNames
array to the corresponding employees in the employees
object.
const lastNames = ["Smith", "Anderson"];
const employees = [
{
name: "Jim",
familyName:"",
},
{
name: "Jill",
familyName: "",
}
];
I attempted to accomplish this task by creating a function called lastNameUpdater
, which should return a new array of objects with updated full names. However, I seem to have taken a wrong turn, possibly due to mismatched index numbers:
function lastNameUpdater(arr, objArr) {
let matchNumber = arr.findIndex() === objArr.findIndex();
const fullNames = objArr.map((element) => {
return matchNumber;
if (matchNumber) {
return objArr.key = arr;
}
return fullNames;
})
}
lastNameUpdater(lastNames, employees);