美文网首页
TypeError: Can not read property

TypeError: Can not read property

作者: 莫wen | 来源:发表于2019-03-24 13:01 被阅读0次

在使用split() ; 方法之前,需要先进行判断

如下实例:

//
var  str = input ? input.split(',') : [];

// 或者
if(!input){
    var str =  input.split(',');
}

//
if(input != undefined){
    var str = input.split(',');
}

如下使用方式错误:

var str = input.split(',');

相关文章

网友评论

      本文标题:TypeError: Can not read property

      本文链接:https://www.haomeiwen.com/subject/yefuvqtx.html