的“取代”我想所有的数组元素转换为null
如果有的undefined
:无法读取属性未定义的错误
console.log(MyThing[7]); //undefined.
for (var i = 0; i < 8; i++) {
if ($(".row.mine") != null) {
if (typeof MyThing[i] === undefined) {
MyThing[i] = null;
} else {
MyThing[i] = MyThing[i].replace(/Aa.*/, '').replace("-", "");
}
} else {
if (typeof MyThing[i] === undefined) {
MyThing[i] = null;
}
}
}
但是,这给了我一个错误Cannot read property 'replace' of undefined
。所以元素不会被转换,如果他们是undefined
。我应该如何改变我的代码来实现这一目标?
尝试设置'undefined'到报价=>''undefined'' – messerbill