javascript - replace first and last occurrence of / with empty -
for /add/id/
should give add/id
i tried using replace(), replaces first occurrence. there way replace both first , last occurrence of / in single step?
you can split() string on / , slice array leaving first , last values , join on /
var str = '/add/id/'; const result = str.split('/').slice(1, -1).join('/'); console.log(result);
Comments
Post a Comment