javascript - Replace Last Character of String -


i want replace last character in string word.

eg, 'flight 12345 a' , want 'flight 12345 auckland' last character can w, c, d, q stand different city names.

how can go achieving js / jquery??

thanks heaps in advance!

you can define map of different city names , replacement passing function callback replace function :

var airports = {      a: 'auckland',      c: 'city2'      ... }; var str2 = str.replace(/\w$/, function(l) { return airports[l] }); 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -

php - Accessing static methods using newly created $obj or using class Name -