Extracting Substrings
JS · Stringssyntax
str.slice(start, end)
str.substring(start, end)example
const path = "/users/profile/avatar.png";
console.log(path.slice(1)); // "users/profile/avatar.png"
console.log(path.slice(-10)); // "avatar.png"
console.log(path.slice(7, 14)); // "profile"Note slice() supports negative indices (counts from end). substring() does not. Prefer slice() -- it is more predictable.