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

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

#1

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


#2

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make easier to read.

Note: Backticks are not single quotes.

See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.


#3

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.

#4

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


#5

I did not see any backticks used in your post, which is why I added them.


#6

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


#7

thank you so much! .


#8

I don’t know what you tried before, because I can only see what your final post was when you clicked Create Topic.