내 코드
const filterSource = list.filter((src) => {
return src.replace(" ", "").includes(search);
});
오류 내용
The "replace is not a function" error occurs when we call the replace() method on a value that is not of type string. To solve the error, convert the value to a string using the toString() method before calling the replace() method.
replace() 를 string이 아닌 값에 쓰면 발생하는 오류였다.
https://bobbyhadz.com/blog/javascript-replace-is-not-a-function
TypeError: replace is not a function in JavaScript | bobbyhadz
The "replace is not a function" error occurs when we call the `replace()` method on a value that is not of type `string`. To solve the error, convert the value to a string using the `toString()` method before calling the `replace()` method.
bobbyhadz.com
문제 해결
replace()를 사용할 값을 toString() 메소드를 사용하여 문자열로 바꿔주면 된다.
const filterSource = list.filter((src) => {
src = src.toString();
return src.replace(" ", "").includes(search);
});
'Language > JavaScript' 카테고리의 다른 글
[JS] 쿠키 set get delete (0) | 2022.11.29 |
---|---|
[JS] axios get post 사용하기.... (230214 수정) (0) | 2022.11.28 |
[JS] href 표현식 <a href=“javascript:;”> </a> (1) | 2022.10.08 |
[JS] location.reload() 사용법 (0) | 2022.09.30 |
[JS] Uncaught TypeError: Cannot read property 'addEventListener' of null (1) | 2022.09.30 |