I want to replace last comma in a string with and... for eg
var ambassadorName = test, test, test
the output must be
var ambassadorName= test, test and test.
Please help me with the code
Using regex you can do:
ambassadorName.replace(/,(?=[^,]*$)/, ' and')
I hope it works.
You can do it like this:
var ambassadorName = "test, test, test";
ambassadorName = ambassadorName.replace(/,([^,]*)$/, 'and $1');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With