JSFiddle - React, Tailwind, and code Playground

by Lloyd Atkinson

JavaScript

const animals = [
	{ type: 'Sheep', colour: 'red'},
    { type: 'Sheep', colour: 'black'},
    { type: 'Dog', colour: 'black'},
    { type: 'Dog', colour: 'yellow'},
    { type: 'Dog', colour: 'yellow'},
    { type: 'Dog', colour: 'red'},
    { type: 'Cat', colour: 'red'},
    { type: 'Cat', colour: 'red'},
    { type: 'Cat', colour: 'red'},
    { type: 'Cat', colour: 'yellow'},
    { type: 'Mouse', colour: 'red'},
    { type: 'Mouse', colour: 'red'},
];
console.log(animals);

const filteredYellow = animals.filter(animal => animal.colour === 'yellow');
console.log(filteredYellow);

const filteredRedCats = animals.filter(animal => animal.type === 'Cat' && animal.colour === 'red');
console.log(filteredRedCats);

const filteredRedCats2 = animals
	.filter(animal => animal.type === 'Cat')
    .filter(animal => animal.colour === 'red');
    
console.log(filteredRedCats2);