JSFiddle - React, Tailwind, and code Playground
by Haze32
JavaScript
function removeLastPathSegment(url) {
return url.substring(0, url.lastIndexOf('/'));
}
// Example usage:
const url = '/path/to/resource';
const modifiedUrl = removeLastPathSegment(url) + "/";
console.log(modifiedUrl); // Output: https://example.com/path/to