Array Slice in JavaScript
Level 258 keystrokes
slice() returns a shallow copy of a portion of an array without modifying the original.
JavaScript code
// Create an array with five numbers1let nums = [1, 2, 3, 4, 5];// slice(start, end) extracts from index 1 to 4 (exclusive)// Returns [2, 3, 4] without modifying the original2console.log(nums.slice(1, 4));Output
[ 2, 3, 4 ]
Practice typing this code. Results are not recorded in the rankings.
Symbols in this code
The symbols you type in this JavaScript code and how often they appear.
,× 5;× 2.× 2(× 2)× 2[× 1]× 1=× 1