I would like to add value to my URL after the specific text. How I can achieve this?
I found a solution where I can slice and add values but I don't have the index fixed in this URL.
const url = 'www.website.com/api/test1/test2';
const url = 'www.website.test.com/api/test1/test2/test3';
const output1 = 'www.website.com/api/ha/test1/test2';
const output2 = 'www.website.test.com/api/ha/test1/test2/test3';
If you want to add a certain value after a certain string you can simply replace the known value with the new string:
url.replace('/api', '/api/ha')
If you don't have a fixed index, you should use Regex to search the string. Could look like this:
/(www.\D+\/api\/)[\D\d\/]+/gm
This code would put the before and after into a group and you can then do
group1 + yourstring + group2
to add it together.