정리/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") || '-'; 이렇게 했음. 값이 없으면 '-' 이 들어감