Extracts a section of a string and returns it as a new string.
Syntax
str.slice(beginIndex, endIndex?)Example
Enter values below to update the example in real time.
const→arr→console→slice→const arr = [1, 2, 3, 4, 5];
console.log(arr.slice(1, 3)); // [2, 3]
console.log(arr.slice(-2)); // [4, 5]