15 must-know JavaScript array methods in 2020
Originally posted on my blog
In JavaScript, an array is a special variable that is used to store different elements. It has some built-in properties and methods we can use to add, remove, iterate, or manipulate data following our needs. And knowing J...
hashnode.com
In the example you gave,
// Instead of using this way myAwesomeArray.some(test => { if (test === "d") { return test } }) // We'll use the shorter one myAwesomeArray.some(test => test === "d")the two functions are not equivalent. In the first case you return either an element of the array or
undefined(as opposed to the realbooleanreturned by the second case). It will work here (as the returned value is either truthy or falsy), but might give you trouble in other cases. The long version of the second function would be the following:myAwesomeArray.some(test => { return test === "d"); }