Skip to content

Commit acf305c

Browse files
committed
javascript-101/arrays: add info on second parameter of .slice()
1 parent 97dde7a commit acf305c

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

page/javascript-101/arrays.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ myArray.shift(); // [ 2 , 7 ]
160160

161161
### .slice()
162162

163-
Extracts a part of the array and returns that part in a new array. This method takes one parameter, which is the starting index:
163+
Extracts a part of the array and returns that part in a new array. This method takes one required parameter, which is the starting index:
164164

165165
```
166166
// Slicing
@@ -172,6 +172,12 @@ console.log( myArray ); // [ 1, 2, 3, 4, 5, 6, 7, 8 ]
172172
console.log( newArray ); // [ 4, 5, 6, 7, 8 ]
173173
```
174174

175+
The `.slice()` method takes an optional second parameter, the end index.
176+
177+
```
178+
console.log( [ 1, 2, 3, 4, 5, 6, 7, 8 ].slice( 2, 5 ) ); // [ 3, 4, 5 ]
179+
```
180+
175181
### .splice()
176182

177183
Removes a certain amount of elements and adds new ones at the given index. It takes at least three parameters:

0 commit comments

Comments
 (0)