Use a regex replacement to look for the last "/" and replace it with "/t_". Difficult to read with the escapes but:
"http://test.com/backgrounds/testimage.jpg".replace(/\/([^\/]*)$/, "/t_$1");
Swap out the string with whatever other string or variable you want to operate on.
Alternately use something to parse the URL if you want more control or just prefer more readability.
Or alternately you could also remove the "/" from the pattern and the substitution. I was hoping JS had a non-regex replaceLast but that doesn't seem to be the case.