Skip to content

Instantly share code, notes, and snippets.

@ibuziuk
Last active January 23, 2023 17:07
Show Gist options
  • Save ibuziuk/fd994471f5681ea64f74b4cb12c7f353 to your computer and use it in GitHub Desktop.
Save ibuziuk/fd994471f5681ea64f74b4cb12c7f353 to your computer and use it in GitHub Desktop.
// map with arrow function
const names = ['Ilya', 'Alena', 'Nadia', 'Sasha'];
const members = names.map((name, index) => "member " + index + " " + name);
console.log(names);
console.log(members);
// map with function
const names = ['Ilya', 'Alena', 'Nadia', 'Sasha'];
const members = names.map(function(name, index) {
return "member " + index + " " + name;
});
console.log(names);
console.log(members);
// map with function expression
const names = ['Ilya', 'Alena', 'Nadia', 'Sasha'];
const namesToMembers = function (name, index) {
return "member " + index + " " + name;
}
const members = names.map(namesToMembers);
console.log(names);
console.log(members);
// map with function declaration
const names = ['Ilya', 'Alena', 'Nadia', 'Sasha'];
function namesToMembers(name, index) {
return "member " + index + " " + name;
}
const members = names.map(namesToMembers);
console.log(names);
console.log(members);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment