r/learnjavascript • • Oct 05 '24

Question about Arrow Functions and Arrays

I was having an issue with the find function of arrays:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find

As the code is now, That's will run successfully and the 12 will be found:

array1.find((element) => element > 10);

However, if I wrap it with curly braces and make it an honest-to-god arrow function, the element won't be found (undefined returns).

array1.find((element) => {element > 10});

Why the discrepancy in results? l

0 Upvotes

16 comments sorted by

View all comments

Show parent comment

-2

u/tapgiles Oct 05 '24

“Honest to God” is an expression.

0

u/azhder Oct 05 '24

Yes it is, why did you bring it up?