IE에서 forEach 오류원인

오류 원인

IE 브라우저에서는 document.querySelectorAll()이 반환하는 NodeList 객체에 대해서는 forEach 메서드를 지원하지 않는다.

오류 해결

[…document.querySelectorAll()].forEach() 와 같이 NodeList 객체를 배열로 바꿔 배열의 forEach 메서드를 사용해야한다.

배열로 변환해야하는 더 중요한ㄴ 이유

HTMLCollection 객체와 NodeList 객체는 모두 배열로 변환하여 사용하는 것을 권장한다.