Use the map Method to Extract Data from an Array:why didnt mine work

So I am trying to do the challenge, got stuck and went to the fcc forum to find the answers. Apparently this is an answer:

let rating = watchList.map((x) => {return {title: x.Title , rating: x.imdbRating}});

What i want to know is why did mine not work? I followed the reasoning from other sites that were teaching on how to use the map function and honestly i dont know how that led to the answer above. This is what i got:

rating = watchList.map((title, rating, i, watchList) => {title= watchList[i]["Title"], rating = watchList[i]["imdbRating"]})

This is the site i was using to try and figure out the code:

How did the person or people who figured out the correct answer, know to put x in the () and then use dot notation on it? I am confused

Hey Deedee,

Here, each element of array watchList is considered as x once as the map function loops through the array. Now, since element of array watchList is an object, we use dot notation.

Hope this helps.

i did use the backticks and in the previews it just a blank grey box and no code

thats what i am saying. i tried using backticks before and it gave me a blank grey box so i discarded the ticks

thank you so much! .

1 Like