javascript - how to add string to url before the last string -
i want add string in between url
i have url
hostname.com/test1/test
i want add test2 before test
it should hostname.com/test1/test2/test
do need break strings / , again build string adding tests?
or there other way can work on?
var url ="hostname.com/test1/test"; var lastslash = url.lastindexof("/"); var output = url.substring(0,lastslash) + "/test2" + url.substring(lastslash, url.length); console.log(output);
hope helps.
Comments
Post a Comment