본문 바로가기
개발/유용한코드

[javascript] includes() 작동 안함

by 경주초이 2020. 6. 10.

대부분의 브라우저가 includes()를 지원하지 않는다고 한다.

비교 객체가 String type이면

if( 객체.indexOf("stage1") > -1) {}

 

또는 polyfill을 사용

if (!String.prototype.includes) {
    String.prototype.includes = function() {
        'use strict';
        return String.prototype.indexOf.apply(this, arguments) !== -1;
    };
}

'개발 > 유용한코드' 카테고리의 다른 글

[SVN] 파일 이름 변경시 에러 발생  (0) 2020.06.22
소셜공유  (0) 2020.03.02
파일업로드_javascript  (0) 2020.03.02
프로세스 관리-02  (0) 2020.02.26
프로세스 관리-01  (0) 2020.02.26