Hello World...
replaceAll method 만들기 본문
javascript split method 와 join method 를 이용해서 replaceAll method 를 구현해 볼 수 있다.
String.prototype.replaceAll = function(searchVal, replaceVal) {
return this.split(searchVal).join(replaceVal);
};
const str = 'hello';
let changeStr = str.replaceAll('l', '1'); // 'he11o'
changeStr; // 'he11o;
str; // 'hello'
How working split method and join method
'javascript' 카테고리의 다른 글
javaScript Promise 헷갈리는 점 추가 (0) | 2020.02.05 |
---|---|
es6 promise 예제 만들어보기 (0) | 2020.02.04 |
encodeURIComponent (0) | 2020.01.14 |
Object.create(obj) 와 new 차이? (0) | 2020.01.11 |
자바스크립트 CLASS (0) | 2020.01.03 |
Comments