From 3296aa2ca50bb031227449486550c503b0f1eaf8 Mon Sep 17 00:00:00 2001 From: Arthur Verschaeve Date: Wed, 14 Jan 2015 07:35:00 +0100 Subject: [PATCH] javascript-101/arrays: add info on second parameter of `.slice()` Fixes gh-611 Closes gh-612 --- page/javascript-101/arrays.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/page/javascript-101/arrays.md b/page/javascript-101/arrays.md index 8c995939..ebd77d43 100644 --- a/page/javascript-101/arrays.md +++ b/page/javascript-101/arrays.md @@ -172,6 +172,12 @@ console.log( myArray ); // [ 1, 2, 3, 4, 5, 6, 7, 8 ] console.log( newArray ); // [ 4, 5, 6, 7, 8 ] ``` +The `.slice()` method takes an optional second parameter, the end index. + +``` +console.log( [ 1, 2, 3, 4, 5, 6, 7, 8 ].slice( 2, 5 ) ); // [ 3, 4, 5 ] +``` + ### .splice() Removes a certain amount of elements and adds new ones at the given index. It takes at least three parameters: