As someone new to learning JavaScript, I have encountered a challenge that has left me stumped for quite some time. My task involves working with an array containing objects representing different animals, including details such as their species, names, and the noises they make. I am tasked with creating a function that takes two parameters: a String representing the name of an animal to search for, and an Array containing all the animal objects. However, my current solution seems to be ineffective:
function search(array, string){
if (array.indexOf(string) !== -1){
return string[animals];
}
else{
return null;
}