I want to search an address string.
if ” Southeast ” is found, replace it with ” SE “;
if ” Southwest ” is found, replace it with ” SW “;
if ” northeast ” is found, replace it with ” NE “;
if ” northeast ” is found, replace it with ” NW “.
Here is what I did so far:
var searchStr = [" Southeast ", " Southwest ", " Northeast ", " Northwest "];
var replaceStr = [" SE ", " SW ", " NE ", " NW "];
var oldAddress = $("#address").text();
for (i=0;i<searchStr.length;i++){
var n = oldAddress.match(/this[i]/g);
if(n != null){
$("#address").text(replaceStr[i]);
}
}
It didn’t do anything, am I missing something?
1 Answer