Is -item- a keyword of javascript or where is it comming from?


const result = {
success: ["max-length", "no-amd", "prefer-arrow-functions"],
failure: ["no-var", "var-on-top", "linebreak"],
skipped: ["no-extra-semi", "no-dup-keys"]
};
function makeList(arr) {
// Cambia solo el código debajo de esta línea
const failureItems = arr.map(item => `<li class="text-warning">${item}</li>`);
// Cambia solo el código encima de esta línea

return failureItems;
}

const failuresList = makeList(result.failure);
  **Información de tu navegador:**

El agente de usuario es: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.0.0 Safari/537.36

Desafío: Crea cadenas usando plantillas literales

Enlaza al desafío:

The map method goes through the array one item at a time and automatically passes each item into the callback function you supply. The callback function needs to accept at least one argument, which is the item being passed into it by map. In order for a function to accept an argument you have to give it a name in the function parameter list, for example:

function (item) { 
  // You can use item in the function body
}

But instead of using a traditional function definition you are using an arrow function for the callback. But it’s still the same thing, you are giving the function parameter the name item. You don’t have to use item, you can call it whatever you want, but usually you want to name it something that makes sense based on what is stored in the array.

1 Like

thank you very much bbsmooth, that was my doubt. if the word item was mandatory.
i got confused as sometimes we see functions with emply parameter, but now i see, since .map works with arrays, it is necesary.
also the explanatoin of how .map works is very clear.
thank you (❁´◡`❁)

but usually you want to name it something that makes sense based on what is stored in the array

Just to add on to what @bbsmooth is saying, the rule of thumb I try to follow is to name my arrays with a plural, then when using map(), filter(), or anything that iterates over the array, name the argument the singular.

dogs.map((dog) => {
  // ...
});

profiles.filter((profile) => {
  // ...
});

people.every((person) => {
  // ...
});
1 Like

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