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
Post a Comment