본문 바로가기
개발/javascript

자바스크립트 replaceAll 기능

by ㅣ푸른하늘ㅣ 2017. 10. 23.
반응형

String.prototype.replaceAll = replaceAll;
function replaceAll(strValue1, strValue2) {
var strTemp = this;

while(1)
{
if (strTemp.indexOf(strValue1) != -1)
strTemp = strTemp.replace(strValue1, strValue2);
else 
break;
}

return strTemp;
}

String.prototype.replaceAll = replaceAll;
function replaceAll(strValue1, strValue2) {
var strTemp = this;

strTemp = strTemp.replace(new RegExp(strValue1, "g"), strValue2);

return strTemp;

}

반응형

'개발 > javascript' 카테고리의 다른 글

jquery .focus  (0) 2018.07.20
비슷한 ID를 가진 값을 each하기  (0) 2018.07.20
Client PC / 모바일 확인하기  (0) 2018.07.10
[NODEJS]PSD 파일 썸네일 추출  (0) 2017.12.06
비밀번호 복잡도(자바스크립트)  (0) 2017.10.23