end_address = 'joe's home, 123 test avenue, los angeles, ca, usa 90210';
end_address = end_address.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});
The outcome of this code will be:
Joe's Home, 123 Test Avenue, Los Angeles, Ca, Usa 90210
However, the preferred result is:
Joe's Home, 123 Test Avenue, Los Angeles, CA, USA 90210
Is there a way to modify the code so that "CA
" and "USA
" are always in uppercase like the desired outcome?