티스토리 뷰

출처 : http://stackoverflow.com/questions/5069464/replace-multiple-strings-at-once

 String.prototype.replaceArray = function (find, replace) {
     var replaceString = this;
     for (var i = 0; i < find.length; i++) {
         // global replacement
         var pos = replaceString.indexOf(find[i]);
         while (pos > -1) {
             replaceString = replaceString.replace(find[i], replace[i]);
             pos = replaceString.indexOf(find[i]);
         }
     }
     return replaceString;
 };
     var textT = "Hello world,,,,, hello people.....";
     var find = [".",","];
     var replace = ['2', '5'];
     textT = textT.replaceArray(find, replace);


댓글
댓글쓰기 폼