4 ms·
> It also has no "break" functionality , which is important if we are talking about performance (i.e. when iterating the array to find a specific member). The
by sheetjs 9y ago
> It also has no "break" functionality , which is important if we are talking about performance (i.e. when iterating the array to find a specific member).
The article is woefully misinformed regarding `forEach` and I agree that the array methods in general are slower [1], but `some` will bail out on the first true value returned. To be sure:
[1,2,3,4,5].some(function(n) { console.log(n); return n>=2; });
will not run the callback function after processing the 2
[1] https://news.ycombinator.com/item?id=7938173 https://news.ycombinator.com/item?id=7938173
- gbuk2013 9y ago"some" !== "forEach" ;) Also, "some" still has the performance penalty of an extra function call per iteration (as I know you know based on your linked comment) and we are talking about performance advice here. But good point - I've never actually used "some" before, so I learn something new today - thanks :)