Cannot read property 'indexOf' of undefined

三世轮回 提交于 2019-12-04 05:58:05

If you are doing that in a loop, you keep overriding the array!

var disableDates = new Array();
disableDates[123] = 123;
console.log(disableDates[123]);  //123

var disableDates = new Array();
disableDates[456] = 456;
console.log(disableDates[123]);  //undefined

Move the array declaration outside of the loop or check if it exists before creating a new Array.

you can test the string first, then use indexOf, for example:

var mydate;
for(i=0; i<mydate.length; i++) {
    if( mydate[i] ) {
        if(mydate[i].indexOf("some") {
              alert("OK");
        }
     }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!