Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- toy project
- react-hook-form
- css
- html
- wescanner
- javascript
- 문제
- 구조분해할당
- TIL
- 이중map
- next.js
- miniproject
- useEffect
- useForm
- ToyProject
- 팀프로젝트
- wecode
- Tanstack Query
- project
- 일본 우편번호 api
- mini
- React
- teamproject
- 다중map
- 구조화된 데이터
- 리액트네이티브
- JS
- Threppa
- 처음부터 배포까지
- 다음은 메인페이지
Archives
- Today
- Total
블로그 이름을 입력해주세요
자바스크립트 replace() 본문
replace() 메서드는 어떤 패턴에 일치하는 일부 또는 모든 부분이 교체된 새로운 문자열을 반환합니다. 그 패턴은 문자열이나 정규식이 될 수 있으며, 교체 문자열은 문자열이나 모든 매치에 대해서 호출된 함수일 수 있습니다.
replace()
// 1
const str = "hello superman";
console.log(str.replace("superman","batman"));
// "hello batman"
// 2
const str = "hello superman";
const a = "superman";
const b = "batman";
console.log(str.replace(a, b));
// "hello batman"
array replace()
// 1
const str = ["superman", "batman"];
console.log(str[0].replace("superman", "wonderwoman")); // "wonderwoman"
console.log(str[1].replace("batman", "aquaman")); // "aquaman"
// 2
const str = ["superman", "batman"];
const ary = [];
ary.push(str[0].replace("superman", "wonderwoman"));
ary.push(str[1].replace("batman", "aquaman"));
console.log(ary); // ["wonderwoman", "aquaman"];
array forEach replace()
// 1
const str = ["superman", "batman", "wonderwoman", "aquaman"];
str.forEach(function(list) {
console.log(list.replace("superman", "flash"));
// "flash"
// "batman"
// "wonderwoman"
// "aquaman"
})
// 2
const str = ["superman", "batman", "wonderwoman", "aquaman"];
str.forEach(function(list) {
console.log(list.replace(list, "flash"));
// "flash"
// "flash"
// "flash"
// "flash"
})
'javaScript' 카테고리의 다른 글
this에 대해 알아봅시다! (0) | 2022.12.23 |
---|---|
javascript callback function (0) | 2022.12.21 |
자바스크립트 ES6 문법을 통한 입력값 주기 Feat. React (0) | 2022.11.23 |
Javascript function(함수) 사용 해보기 (0) | 2022.10.04 |
[React] Recharts 라이브러리 (0) | 2022.07.31 |