개발/유용한코드
[javascript] includes() 작동 안함
경주초이
2020. 6. 10. 10:53
대부분의 브라우저가 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;
};
}