Created
August 30, 2019 01:54
-
-
Save dottedsquirrel/9d1fab679c8f6afa9d6ea51453fe714b to your computer and use it in GitHub Desktop.
JavaScript array find()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let animals = [ | |
{name: 'Tibbers', type: 'cat', isNeutered: true, age: 2}, | |
{name: 'Fluffball', type: 'rabbit', isNeutered: false, age: 1}, | |
{name: 'Strawhat', type: 'cat', isNeutered: true, age: 5} | |
] | |
animalTypeFound = animals.find( animal => animal.type === 'cat' ); | |
// animalTypeFound will return: | |
// {name: 'Tibbers', type: 'cat', isNeutered: true, age: 2} | |
animalTypeFilter = animals.filter( animal => animal.type === 'cat' ); | |
// animalTypeFilter will return: | |
// [{name: 'Tibbers', type: 'cat', isNeutered: true, age: 2}, {name: 'Strawhat', type: 'cat', isNeutered: true, age: 5}] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment