Difference between find() and filter().shift() on javascript

后端 未结 2 1967
梦毁少年i
梦毁少年i 2020-12-08 00:12

I recently starting to drop underscore/lodash overuse on (some of) my projects and realize that there\'s no full support of find method in browsers. What\'s the difference b

2条回答
  •  一整个雨季
    2020-12-08 00:43

    Apart from the obvious (and noticeable) overhead, yes, the results might vary. filter runs till the end of the array, and invokes its callback on every item; in contrast to find which stops after having found one. When the callback throws an exception on one of these additionally iterated elements, the outcome is different.
    I don't see any good reason not to use find.

提交回复
热议问题