0

This syntax doesn't work :

        // arrIng = ["semolina", "flour", "or", "cornmeal", "for", "dusting"];
        // unitShort = ['tbsp','tbsp','oz','oz','tsp','tsp','cup','pound'];

        const unitIndex = arrIng.findIndex((el2)  => {
        unitShort.includes(el2)
        });

        console.log(unitIndex); 
        // returns -1

And this syntax works :

        // arrIng = ["semolina", "flour", "or", "cornmeal", "for", "dusting"];
        // unitShort = ['tbsp','tbsp','oz','oz','tsp','tsp','cup','pound'];

        const unitIndex = arrIng.findIndex(el2  => unitShort.includes(el2));
        console.log(unitIndex); 
        // returns 2

If anyone can explain why is that or at least send resource that could help me understand that I would greatly appreciate any help.

Patricios
  • 13
  • 3
  • 4
    It's *valid syntax*, however in the first case the arrow function doesn't return anything. If you have `{ }` around the body, you need an explicit `return` statement. When you use the shorthand without `{ }` it implicitly returns the value. – VLAZ Jul 09 '20 at 13:21

0 Answers0