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
It modified`arr` starting from the index `start`: removes `deleteCount` elements and then inserts `elem1, ..., elemN` at their place. Returns the array of removed elements.
47
+
It modifies`arr` starting from the index `start`: removes `deleteCount` elements and then inserts `elem1, ..., elemN` at their place. Returns the array of removed elements.
48
48
49
49
This method is easy to grasp by examples.
50
50
@@ -700,7 +700,7 @@ alert(soldiers[1].age); // 23
700
700
701
701
If in the example above we used `users.filter(army.canJoin)`, then `army.canJoin` would be called as a standalone function, with `this=undefined`, thus leading to an instant error.
702
702
703
-
A call to `users.filter(army.canJoin, army)` can be replaced with `users.filter(user => army.canJoin(user))`, that does the same. The former is used more often, as it's a bit easier to understand for most people.
703
+
A call to `users.filter(army.canJoin, army)` can be replaced with `users.filter(user => army.canJoin(user))`, that does the same. The latter is used more often, as it's a bit easier to understand for most people.
704
704
705
705
## Summary
706
706
@@ -711,7 +711,7 @@ A cheat sheet of array methods:
711
711
-`pop()` -- extracts an item from the end,
712
712
-`shift()` -- extracts an item from the beginning,
713
713
-`unshift(...items)` -- adds items to the beginning.
714
-
-`splice(pos, deleteCount, ...items)` -- at index `pos`delete`deleteCount` elements and insert`items`.
714
+
-`splice(pos, deleteCount, ...items)` -- at index `pos`deletes`deleteCount` elements and inserts`items`.
715
715
-`slice(start, end)` -- creates a new array, copies elements from index `start` till `end` (not inclusive) into it.
716
716
-`concat(...items)` -- returns a new array: copies all members of the current one and adds `items` to it. If any of `items` is an array, then its elements are taken.
717
717
@@ -729,7 +729,7 @@ A cheat sheet of array methods:
729
729
-`sort(func)` -- sorts the array in-place, then returns it.
730
730
-`reverse()` -- reverses the array in-place, then returns it.
731
731
-`split/join` -- convert a string to array and back.
732
-
-`reduce(func, initial)` -- calculate a single value over the array by calling `func` for each element and passing an intermediate result between the calls.
732
+
-`reduce/reduceRight(func, initial)` -- calculate a single value over the array by calling `func` for each element and passing an intermediate result between the calls.
733
733
734
734
- Additionally:
735
735
-`Array.isArray(arr)` checks `arr` for being an array.
@@ -738,7 +738,7 @@ Please note that methods `sort`, `reverse` and `splice` modify the array itself.
738
738
739
739
These methods are the most used ones, they cover 99% of use cases. But there are few others:
740
740
741
-
-[arr.some(fn)](mdn:js/Array/some)/[arr.every(fn)](mdn:js/Array/every)checks the array.
741
+
-[arr.some(fn)](mdn:js/Array/some)/[arr.every(fn)](mdn:js/Array/every)check the array.
742
742
743
743
The function `fn` is called on each element of the array similar to `map`. If any/all results are `true`, returns `true`, otherwise `false`.
0 commit comments