Substring
Nos devuelve un nuevo string que contiene el segmento que le especificamos
const str = 'https://kuworking.github.io/'
let new_str
new_str = str.substring(8, 11) // -> www
new_str = str.substring(8) // -> kuworking.github.io/
new_str = str.substring(8, str.length - 1) // -> kuworking.github.io
new_str = str.substring(0, str.length - 1) // -> https://kuworking.github.io
new_str = str.substring(0, -1) // no funciona, no acepta números negativosSubstr
En el caso de substr tienes lo mismo que substring, pero mientras antes especificábamos inicio y fin, aquí especificamos inicio y número de carácteres a incluir
const str = 'https://kuworking.github.io/'
let new_str
new_str = str.substr(8, 3) // -> www
new_str = str.substr(8) // -> kuworking.github.io/
new_str = str.substr(8, 17) // -> kuworking.github.io
new_str = str.substr(0, 25) // -> https://kuworking.github.io
new_str = str.substr(0, -1) // no funciona, no acepta números negativosDepende de qué quieras hacer, una opción nos simplificará la vida bastante más que la otra
En este caso, escoger substr sería complicarse sin motivo
Slice
Slice viene a ser lo mismo que substring con la diferencia de que aquí sí se aceptan valores negativos
const str = 'https://kuworking.github.io/'
let new_str
new_str = str.slice(8, 11) // -> www
new_str = str.slice(8) // -> kuworking.github.io/
new_str = str.slice(8, str.length-1) // -> kuworking.github.io
new_str = str.slice(0, str.length-1) // -> https://kuworking.github.io
new_str = str.slice(0, -1) // -> https://kuworking.github.io
new_str = str.slice(-4) // -> com/