Skip to content

Instantly share code, notes, and snippets.

@RaDeleon
Forked from mpj/0-array.js
Created November 9, 2017 03:18
Show Gist options
  • Save RaDeleon/bd51bc69728f5d725a014d496d063574 to your computer and use it in GitHub Desktop.
Save RaDeleon/bd51bc69728f5d725a014d496d063574 to your computer and use it in GitHub Desktop.
Code to the video - "Map: Part 2 of Functional Programming in JavaScript"
var animals = [
{ name: 'Fluffykins', species: 'rabbit' },
{ name: 'Caro', species: 'dog' },
{ name: 'Hamilton', species: 'dog' },
{ name: 'Harold', species: 'fish' },
{ name: 'Ursula', species: 'cat' },
{ name: 'Jimmy', species: 'fish' }
]
var names = []
for (var i = 0; i < animals.length; i++) {
names.push(animals[i].name)
}
var names = animals.map(function(animal) { return animal.name })
var names = animals.map(function(animal) { animal.name + ' the ' + animal.species })
var names = animals.map((animal) => animal.name)
var names = animals.map((x) => x.name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment