Respuesta :
Answer:
1. .forEach( )
// displayNames is the array to hold the name of the animal
const displayNames = [];
// forEach method is called on zooAnimals array. Inside the forEach method
// a String variable temp is declared to hold the name and scientific name of
// the animal in a specified format. Then the string is push into the array.
zooAnimals.forEach(function(element){
var temp = "Name: " + element.animal_name + ", " + "Scientific: " + element.scientific_name
displayNames.push(temp)
})
// the array displayNames is log to the console
console.log(displayNames);
2. .map( )
// The map method return an array and is assigned to lowCaseAnimalNames
// Arrow function is use to perform the mapping. It map each element animal
// name to lower case during each iteration in the array
const lowCaseAnimalNames = zooAnimals.map(element => element.animal_name.toLowerCase());
// the array lowCaseAnimalNames is log to the console
console.log(lowCaseAnimalNames);
3. .filter( )
// The filter method of an array return an array. So, it is assign to
// lowPopulationAnimals. The Arrow function (=>) is used to return only object
// of animals with population less than 5
const lowPopulationAnimals = zooAnimals.filter(element => element.population < 5);
// log the population of animals less than 5 to the console
console.log(lowPopulationAnimals);
4. .reduce( )
// The reduce method of an array also return a single number after operation
// The reduce method has two arguments (accumulator and currentValue)
// The accumulator hold the value of our initial sum which is 0. The
// currentValue represent the current element been handled in the loop
const populationTotal = zooAnimals.reduce((accumulator, currentValue) => accumulator + currentValue.population, 0);
// log the total population of animal in the zoo
console.log(populationTotal);
Explanation: