You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 1-js/05-data-types/05-array-methods/article.md
+6-5Lines changed: 6 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -529,7 +529,7 @@ The methods [arr.reduce](mdn:js/Array/reduce) and [arr.reduceRight](mdn:js/Array
529
529
The syntax is:
530
530
531
531
```js
532
-
let value =arr.reduce(function(previousValue, item, index, arr) {
532
+
let value =arr.reduce(function(previousValue, item, index, array) {
533
533
// ...
534
534
}, initial);
535
535
```
@@ -538,7 +538,7 @@ The function is applied to the elements. You may notice the familiar arguments,
538
538
539
539
-`item` -- is the current array item.
540
540
-`index` -- is its position.
541
-
-`arr` -- is the array.
541
+
-`array` -- is the array.
542
542
543
543
So far, like `forEach/map`. But there's one more argument:
544
544
@@ -613,6 +613,7 @@ So it's advised to always specify the initial value.
613
613
614
614
The method [arr.reduceRight](mdn:js/Array/reduceRight) does the same, but goes from right to left.
615
615
616
+
616
617
## Array.isArray
617
618
618
619
Arrays do not form a separate language type. They are based on objects.
@@ -694,6 +695,9 @@ A cheatsheet of array methods:
694
695
-`includes(value)` -- returns `true` if the array has `value`, otherwise `false`.
695
696
-`find/filter(func)` -- filter elements through the function, return first/all values that make it return `true`.
696
697
-`findIndex` is like `find`, but returns the index instead of a value.
698
+
699
+
- To iterate over elements:
700
+
-`forEach(func)` -- calls `func` for every element, does not return anything.
697
701
698
702
- To transform the array:
699
703
-`map(func)` -- creates a new array from results of calling `func` for every element.
@@ -702,9 +706,6 @@ A cheatsheet of array methods:
702
706
-`split/join` -- convert a string to array and back.
703
707
-`reduce(func, initial)` -- calculate a single value over the array by calling `func` for each element and passing an intermediate result between the calls.
704
708
705
-
- To iterate over elements:
706
-
-`forEach(func)` -- calls `func` for every element, does not return anything.
707
-
708
709
- Additionally:
709
710
-`Array.isArray(arr)` checks `arr` for being an array.
0 commit comments