프로그래밍/Front end

[Front end] JavaScript Object doesn't support property or method 'find' in IE

Reference M1 2020. 2. 18. 22:55

 

find 메서드가 크롬 및 파이어폭스 브라우저에서는 제대로 작동하지만 IE에서는 오류가 발생한다. 해당 함수를 지원하지 않는다는 말이기도 하다. 지원 범위는 아래 사이트에서 확인이 가능하다.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find

 

Array.prototype.find()

The find() method returns the value of the first element in the provided array that satisfies the provided testing function.

developer.mozilla.org

 

// 중복 체크
const checkId = selectList.find((item) => {
	return item === userId;
});

// 중복 체크 IE에서 Array.find Not suport로 인해 범용 filter 적용
const checkId = selectList.filter( function(item) {
	return item === userId
})[0];

이 문제를 해결하는 가장 좋은 방법은 모든 브라우저에서 지원되는 유사한 기능을 가진 jQuery를 사용하는 것이다.