기본 콘텐츠로 건너뛰기

자바스크립트(JavaScript) | IE(Internet Explorer) replaceAll 구현


자바스크립트(JavaScript) | IE(Internet Explorer) replaceAll 구현

IE에는 문자열 함수에 replaceAll이 없어요.




1
2
3
4
5
6
7
8
9
function replaceAll(str, searchStr, replaceStr) {
    return str.split(searchStr).join(replaceStr);
}
 
var str = '111-22-33333';   // 사업자번호
console.log(str);           // 111-22-33333
 
str = replaceAll(str, '-''');
console.log(str);           // 1112233333

댓글