Replace all spaces in a string with ‘+’ [duplicate]

Here’s an alternative that doesn’t require regex:

var str="a b c";
var replaced = str.split(' ').join('+');

Leave a Comment