[Error Log] string.replaceAll is not a function

suno·2023년 1월 11일
post-thumbnail

👀 상황

api 검색어 쿼리 문자를 replacing 하기 위해 replaceAll 메소드를 사용했다.

const titleValue = title.replaceAll(/[\[\]0-9']/g, '_').replaceAll(', '/');

ios에서는 정상 동작하는데, android에서 string.replaceAll is not a function 라는 에러가 발생했다.


❓ 원인

android 환경에서는 replaceAll 메소드가 동작하지 않는다.


✅ 해결

replaceAll 대신 split.join으로 대체했더니 잘 작동한다!

const titleValue = title
  .split(/[\[\]0-9']/g).join('_')
  .split('·').join('/');

Reference
StackOverFlow

profile
Software Engineer 🍊

0개의 댓글