This post is from a low-reputation account and contains an unverified outbound link. Be cautious before clicking external links.

FFC Notes - saving objects to an array

Words
103
Reading
1 min
Listen
Play
8y

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.

FFC Notes - saving objects to an array | Ecency