File tree Expand file tree Collapse file tree 1 file changed +5
-3
lines changed
1-js/05-data-types/05-array-methods Expand file tree Collapse file tree 1 file changed +5
-3
lines changed Original file line number Diff line number Diff line change @@ -275,7 +275,8 @@ Here the [arr.find](mdn:js/Array/find) method comes in handy.
275275The syntax is:
276276``` js
277277let result = arr .find (function (item , index , array ) {
278- // should return true if the item is what we are looking for
278+ // if true is returned, item is returned and iteration is stopped
279+ // for falsy scenario returns undefined
279280});
280281```
281282
@@ -313,11 +314,12 @@ The `find` method looks for a single (first) element that makes the function ret
313314
314315If there may be many, we can use [ arr.filter(fn)] ( mdn:js/Array/filter ) .
315316
316- The syntax is roughly the same as ` find ` , but it returns an array of matching elements:
317+ The syntax is similar to ` find ` , but filter continues to iterate for all array elements even if ` true ` is already returned :
317318
318319``` js
319320let results = arr .filter (function (item , index , array ) {
320- // should return true if the item passes the filter
321+ // if true item is pushed to results and iteration continues
322+ // returns empty array for complete falsy scenario
321323});
322324```
323325
You can’t perform that action at this time.
0 commit comments