Hi, so far this is the first challange I simply wasn’t able to do and frankly It took me a lot of time to even understand one of two solutions in “Hints”, but it still isn’t clear.
const ratings = watchList.map(item => ({
title: item["Title"],
rating: item["imdbRating"]
}));
Above one I think I almost get. I will try to explain it and I’d like to ask you to correct me if I’m wrong:
- it uses map method, and its argument is a callback function, which is going to be applied to every object in an array of objects watchList,
- that callback function uses an arrow function syntax,
- item is an arrow funcion argument, the funcion returns an object
({
title: item["Title"],
rating: item["imdbRating"]
})
- title and rating are property names of the returned object, which means that they are actually strings (js syntax allows us to skip “” for object properties), thats why they are enclosed by quote marks,
- item[“Title”] needs quotation marks because otherwise Title would be confused for some undefined variable named Title
One thing i really don’t understand is wy do I have to enclose the:
{
title: item["Title"],
rating: item["imdbRating"]
}
into parentheses like this for it to work:
({
title: item["Title"],
rating: item["imdbRating"]
})