const s = "your_string"; const withoutLastChunk = s.slice(0, s.lastIndexOf("_")); console.log(withoutLastChunk);