Why do I have to use return inside the map when I already assign it to the ratings array

I used the map here to loop over the watchList array and get some values for the ratings array in the callback function when I did not insert return before the object it shows an error why is that

const ratings = watchList.map((film) => {

  {title: film.Title, rating: film.imdbRating}


challenge link

I’m not sure what exactly you mean.

A map takes a callback function. The input to that callback function is an old array element. The return value of the callback function will be the new array value.

1 Like

Ok I edited the post and explained my problem

A function has no return value unless you return something. And the map has no idea what to put into the new array unless you return something.

1 Like

Ok I understand
aren’t we sometimes gonna use map without inserting return at all

Nope. There should always be a return value. Sometimes the return statement is implicit instead of explicit, but a map callback should always have a return value.

1 Like

what implicit return means in the map array method does it mean not having curly braces that wraps the body of the function


input => "This is an implicit return for " + input


input => {
  return "This is an explicit return for " + input;
1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.