I am trying to assign an IF statement inside a map function but it asks for a return. If I put the return, in front of the IF, does not work. Currently getting the following error on Lint: Line 78:52: Array.prototype.map() expects a return value from arrow function array-callback-return
I expect just to push objects into the array.
What is the correct way to assign the IF inside a map?
{ ingredientIndex.map((currentIndex) => {
const ingredient = detail[`strIngredient${currentIndex}`];
const measure = detail[`strMeasure${currentIndex}`];
if (ingredient) {
validIngredients.push(`${ingredient} - ${measure}`);
}
}) }
Advertisement
Answer
ingredientIndex.forEach(currentIndex => {
^^^^^^^