To remove everything after last backslash with JavaScript, we call the substr and lastIndexOf methods.
For instance, we write
const t = "\\some\\route\\here";
const newT = t.substr(0, t.lastIndexOf("\\"));
to call lastIndexOf to return the last index of '\\'.
Then we call substr to return the substring in t before index 0 and the index returned by lastIndexOf.