Some questions about map and how it works

I’m feeling especially stupid this morning, but can I please ask for some clarification on this challenge. I want to make sure I’m understanding it. The solution is below. (I had to look at the answer, because I couldn’t figure it out myself.) Here are my questions. I’m just a beginner, so I apologize if I’m not using the correct terminology:

  1. the map function is going to run through all of the elements of the array watchList
  2. We are giving each of those elements the “temporary name/label” of item as it does that iteration
  3. The brackets ( ) enclose the arrow function that is acting on the “items”
    4.Inside that arrow function, the Title and imdbRating are being pulled out by map and added to map’s output array
  4. The curly brackets { } enclose the results we are going to get back, and they are there so that what we get back is an array object.

Your code so far

const ratings = => ({
  title: item["Title"],
  rating: item["imdbRating"]

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.63 Safari/537.36 Edg/102.0.1245.33

Challenge: Use the map Method to Extract Data from an Array

Link to the challenge:

Roughly speaking, the map looks something like this

function map(arr, func) {
  const res = [];

  for (let i = 0; i < arr.length; ++i) {
    // we're calling func on every element of the array
    // and pushing the result in the resulting array like this
    res[i] = func(arr[i])

  return res;

const ratings = map(watchList, item => ({
  title: item["Title"],
  rating: item["imdbRating"]

Thank you for the concise and clear explanation.

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