String.prototype.replaceAll()

혜진 조·2022년 12월 19일
0

자바스크립트

목록 보기
8/12

특정 문자열 A를 전부 문자열 B로 변환하는 방법

문법

replaceAll(pattern, replacement)

예시

const p = 'The quick brown fox jumps over the lazy dog. If the dog reacted, was it really lazy?';

console.log(p.replaceAll('dog', 'monkey'));
// expected output: "The quick brown fox jumps over the lazy monkey. If the monkey reacted, was it really lazy?"


// global flag required when calling replaceAll with regex
const regex = /Dog/ig;
console.log(p.replaceAll(regex, 'ferret'));
// expected output: "The quick brown fox jumps over the lazy ferret. If the ferret reacted, was it really lazy?"

const date = 2022-12-13
console.log(data.replaceAll("-","."))
//expected output:"2022.12.13"
profile
나를 믿고 한 걸음 한 걸음 내딛기! 🍏

0개의 댓글