**Your browser information:**
User Agent is: <code>Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36</code>.
**Challenge:** Use the map Method to Extract Data from an Array
**Link to the challenge:**
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/functional-programming/use-the-map-method-to-extract-data-from-an-array
map doesn’t accept two functions as parameters, only one
so the callback function in this way is returning a string title => title.Title and the map method is creating a new array where in place of the objects that were in the original array now there are strings
what kind of data type does it needs to be if not a string? an array, an object?
make your callback function return that data type
watchList is an array of objects with various properties. title is a property of that object containing a string.
Ok so I need to return an object; the syntax eludes me. This doesn’t work either:
title is the object (maybe not the best parameter name… I think it is confusing you - why don’t you use obj or something as parameter name?)
do you want that as property value? or you want something from inside it as property value?
you are not returning an object, but you are getting one of the values you wanted, aren’t you?
you just need to put that one inside the right data structure
Just with respect to the difficulties you are having with syntax: you don’t need to complicate things further by trying to figure out the subtleties of arrow functions as well, you can just write it in the way you’ve been shown many times earlier in the course
.map(function (argument) {
return // thing you are doing with argument
});
So in reading the challenge I totally missed that “title” and “rating” were to be the new object keys in a returned array and instead I was trying to return just an array containing the Title and imdbRating properties only (basically a double array). DUH
(which STILL doesn’t work, and only returns the rating…why?) and when I compared with what the challenge said I should be getting I realized I was leaving out the part with “title” and “rating” keys altogether. Now I totally “get” what @camperextraordinaire was hinting at the entire time. I ended up with this.
Thank you @ilenia for cluing me in with my confusion regarding “title”… Sorry for my poor reading comprehension folks! Wow that was my entire Sunday!
Cheers