I'm working on javascript array and need to write a function that takes the first index of the array below and returns an array of the objects' names.
var animals = [
{
name: 'murphy brown the dog',
type: 'dog',
age: 4,
fav_toy: 'squeaky octopus'
},
{
name: 'mervin',
type: 'cat',
age: 1,
fav_toy: 'catnip mouse'
},
{
name: 'peppercorn',
type: 'cat',
age: 3,
fav_toy: 'lady bug pillow'
},
{
name: 'willa',
type: 'cat',
age: 4,
fav_toy: 'jingle ball'
},
]
Here's my function:
function getName(animals){
console.log(animals[0]);
return (animals[0]);
}