Provided with a file path like new/lib/java.exe, I am looking to eliminate the root folder 'new' and structure the new path as lib/java.exe.
Challenge: After my attempts, I am left with the path as lib/java.exe/ which includes an unwanted "/". I want to avoid having "/" at the end of the path. Please review the code snippet below that I have been working on. Any assistance in solving this issue would be greatly appreciated.
function myFunction() {
var path='';
var str = "new/lib/java.exe";
var res = str.split("/");
if(res.length > 0)
res.shift();
for(var i=0; i < res.length; i++){
if(res.length == 1){
path = res[i];
}
else{
path += res[i] + "/";
}
}
document.getElementById("demo").innerHTML = path;
}