FFC Notes - saving objects to an array

in freecodecamp •  6 years ago 

Table of Contents

When solving Functional Programming: Use the map Method to Extract Data from an Array, I came across a couple unexpected issues.

The first, was when I was trying to push the object to the newRating array, but was just getting an array indexes back.

watchList.map( (a) => newRating.push({"title": a["Title"],  "rating": a["imdbRating"]} ))
(5) [6, 7, 8, 9, 10]


Next I tried to save the output of the array to a new variable, but got another error.

 var newRating = watchList.map( (a) => {"title": a["Title"],  "rating": a["imdbRating"]} )
 VM1046:1 Uncaught SyntaxError: Unexpected token :


I did a search on arrow function notation and found I had to use parenthesizes to return an object literal. Based off MDN's Object literals section, without the parenthesizes
the code is interpreted as a code block statement.

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Congratulations @rdes! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 2 years!

You can view your badges on your Steem Board and compare to others on the Steem Ranking

Vote for @Steemitboard as a witness to get one more award and increased upvotes!