let path = "/bar/foo/moo/"; let split = path.split("/"); let splicedStr = split.slice(0, split.length - 2).join("/") + "/"; console.log(splicedStr); //outputs: /bar/foo/