.
function urlappend(url, append) {
return url.replace(/(?=\?)|$/, append);
}
urlappend('http://example.com?bob=true', '/search/results');
urlappend('http://example.com', '/search/results')
(?=\?) ? .
Regarding whether this is the โrightโ way, it is subjective. I would say if the links you are dealing with are just strings, not nodes, thatโs better. If they are already connected, use the karim79 method.
source
share