I have a function that looks like this:
function createModifiedList(people){
const modifiedList = []
for (let i = 0; i < people.length; i++){
modifiedList.push({
name: person.firstName + " " + person.lastName,
jobTitle: person.jobTitle,
})
}
return modifiedList
}
Given a list of people, this function constructs a slightly altered version of the original list.
I am wondering if there is a way to pass an object that gets constructed during any step of the for loop as a parameter?
I aim to make this function modular for future reuse. In my actual codebase, which is much larger, this change would greatly enhance its efficiency, although the scenario remains similar.
Therefore, I would like to include an argument where I can input something like:
{
name: person.firstName + " " + person.lastName,
jobTitle: person.jobTitle,
}
And for subsequent function calls, I could provide:
{
name: person.firstName + " " + person.lastName,
bio: person.bio,
}
The method should then recognize that this is the object that needs to be added at each iteration of the for-loop.
Is there a way to achieve this functionality?
Thank you!