Skip to content

Instantly share code, notes, and snippets.

@ShaileshPrajapati-BTC
Last active August 17, 2018 10:08
Show Gist options
  • Save ShaileshPrajapati-BTC/7febe85d6d49ecf9a098635088d68c8f to your computer and use it in GitHub Desktop.
Save ShaileshPrajapati-BTC/7febe85d6d49ecf9a098635088d68c8f to your computer and use it in GitHub Desktop.
const animals = [
{
"name": "cat",
"size": "small",
"weight": 5
},
{
"name": "dog",
"size": "small",
"weight": 10
},
{
"name": "lion",
"size": "medium",
"weight": 150
},
{
"name": "elephant",
"size": "big",
"weight": 5000
}
]
//Map Method
let animal_names = animals.map((animal, index, animals) => {
return animal.name
})
console.log(animal_names)
["cat", "dog", "lion", "elephant"]
// Filter Method
// Ffind the animals whos size is small
let small_animals = animals.filter((animal) => {
return animal.size === "small"
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment