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

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -