정리/ETC

Cannot read property 'indexOf' of undefined

Absolute Devil Vivian 2020. 1. 7. 16:04

....

....

var text = $(this).attr("id");

if(text.indexOf(",") != -1){ ... }

대충 이런게 있다고 하면, Cannot read property 'indexOf' of undefined 이런 뭐같은 애러가 날때가 있음.

var text가 null, undefined 이면 저런 에러가 남.

그래서 나는 var text = $(this).attr("id") || '-'; 이렇게 했음. 값이 없으면 '-' 이 들어감

 

'정리 > ETC' 카테고리의 다른 글

크롬 주소창 검색에 자동 검색 결과가 나옴  (1) 2021.11.02
Visual Studio Code(VSC) 기본 작성 언어 변경  (5) 2021.10.29
[후기] CentOS 7 설치부터 톰캣까지  (0) 2019.08.14
axboot가 뭐야?  (0) 2019.03.25
SQLite  (0) 2018.01.31