function foobar(animal)
{
some function...
}
foobar(animals[1]); // send dog to foobar - js arrays start at 0
or more than one (passing an array means only one parameter needed)
function foobar(subanimals)
{
some function...
}
foobar([animals[1],animals[3]]); // send dog and duck to foobar as an array
Lastly if you do not want to care if you receive an array or a single item
function foobar(subanimals)
{
if (!Array.isArray(subanimals)) subanimals=[subanimals]; //force array
some function...
}
foobar(animals[2]); // send ONLY horse
Also look at array slice
In the last two functions you can do
for (var i=0;i<subanimals.length;i++) {
if (subanimals[i]=="duck") alert("fowl");
else if (subanimals[i]=="horse") alert("ungulate");
else alert("Neither fowl nor horse");
}