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?
JavaScript
x
8
1
{ ingredientIndex.map((currentIndex) => {
2
const ingredient = detail[`strIngredient${currentIndex}`];
3
const measure = detail[`strMeasure${currentIndex}`];
4
if (ingredient) {
5
validIngredients.push(`${ingredient} - ${measure}`);
6
}
7
}) }
8
Advertisement
Answer
JavaScript
1
3
1
ingredientIndex.forEach(currentIndex => {
2
^^^^^^^
3