File tree 1 file changed +5
-3
lines changed
1-js/05-data-types/05-array-methods
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.
275
275
The syntax is:
276
276
``` js
277
277
let 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
279
280
});
280
281
```
281
282
@@ -313,11 +314,12 @@ The `find` method looks for a single (first) element that makes the function ret
313
314
314
315
If there may be many, we can use [ arr.filter(fn)] ( mdn:js/Array/filter ) .
315
316
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 :
317
318
318
319
``` js
319
320
let 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
321
323
});
322
324
```
323
325
You can’t perform that action at this time.
0 commit comments