FFC Notes - saving objects to an array

in #freecodecamp6 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.

Sort:  

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!

Coin Marketplace

STEEM 0.17
TRX 0.15
JST 0.028
BTC 60249.61
ETH 2321.35
USDT 1.00
SBD 2.51