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
+38-37Lines changed: 38 additions & 37 deletions
Original file line number
Diff line number
Diff line change
@@ -122,7 +122,7 @@ The syntax is:
122
122
arr.slice(start, end)
123
123
```
124
124
125
-
It returns a new array where it copies all items start index `"start"` to `"end"` (not including `"end"`). Both `start` and `end` can be negative, in that case position from array end is assumed.
125
+
It returns a new array containing all items from index `"start"` to `"end"` (not including `"end"`). Both `start` and `end` can be negative, in that case position from array end is assumed.
126
126
127
127
It works like `str.slice`, but makes subarrays instead of substrings.
alert(`${item} is at index ${index} in ${array}`);
227
+
});
228
+
```
229
+
230
+
The result of the function (if it returns any) is thrown away and ignored.
231
+
232
+
204
233
## Searching in array
205
234
206
235
These are methods to search for something in an array.
@@ -274,7 +303,7 @@ alert(user.name); // John
274
303
275
304
In real life arrays of objects is a common thing, so the `find` method is very useful.
276
305
277
-
Note that in the example we provide to `find`a single-argument function `item => item.id == 1`. Other parameters of `find` are rarely used.
306
+
Note that in the example we provide to `find`the function `item => item.id == 1` with one argument. Other arguments of this function are rarely used.
278
307
279
308
The [arr.findIndex](mdn:js/Array/findIndex) method is essentially the same, but it returns the index where the element was found instead of the element itself.
alert(`${item} is at index ${index} in ${array}`);
611
-
});
612
-
```
613
-
614
-
The result of the function (if it returns any) is thrown away and ignored.
615
-
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