I've got an array of objects, and have to return the key puppies
in a new array:
This function takes an array of dogs in the format:
[
{breed: 'Labrador', puppies: ['Fluffy', 'Doggo', 'Floof'] },
{breed: 'Rottweiler', puppies: ['Biscuits', 'Mary'] }
]
It should return an array of all the puppies from all the dogs:
['Fluffy', 'Doggo', 'Floof', 'Biscuits', 'Mary']
This is my code so far:
function collectPuppies (dogs) {
let solution=[];
for(let i=0; i<dogs.length; i++){
solution.push(dogs[i].puppies);
}
return solution;
}
It adds the names to solution, but returning them in between [[ ]]
:
Expected [ [ 'Spot', 'Spotless' ] ] to deeply equal [ 'Spot', 'Spotless' ]
I've seen my solution in this thread, so I believe I'm not too far but can't figure out what I'm doing wrong. Can anyone help me out? Thanks in advance.