0

Substrings with slice in JavaScript

Use .slice() to extract substrings given two indices:

var s = "0123456789abcdefg";

console.log(s.slice(0, 5)); // "01234"
console.log(s.slice(5, 6)); // "5"
RUN

Given one index, it will take from that index to the end of the string:

var s = "0123456789abcdefg";

console.log(s.slice(10)); // "abcdefg"
RUN
add comment
Suggest a different solution or add another example