rdes avatar

FFC Notes - saving objects to an array

rdes

Published: 19 Nov 2018 › Updated: 19 Nov 2018FFC Notes - saving objects to an array

FFC Notes - saving objects to an array

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.

Leave FFC Notes - saving objects to an array to:

Written by

Read more #freecodecamp posts


Best Posts From rdes

We have not curated any of rdes's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.

More Posts From rdes