Learn Basic String and Array Methods by Building a Music Player - Step 22

Tell us what’s happening:

In this code, the .find() method is used to find a song object that matches the given id. My question is, does the .find() method return the whole object that contains the matching id, or does it only return the value of the specific property being searched for (in this case, id)?

Step 22, the instructions don’t really explain how it interacts with an array of objects. They only provide an example of using it on an array with simple elements. I just want confirmations to make it clear for me so I can digest it well.

Your code so far

I made some changes to the code so that it won’t get deleted.

const playSong = (id) => {
  const song = Object?.propertArray.find((element) => element.id === id);
  audio.src = propertArray.src;
  audio.title = propertArray.title;
};

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36

Challenge Information:

Learn Basic String and Array Methods by Building a Music Player - Step 22

I would try two things

  1. I’d console.log the return value

  2. I’d ask MDN

It seems to say the first matching element itself is returned

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.