队列任务异常:TypeError: Cannot read property 'length'零
Exception in queued task: TypeError: Cannot read property 'length' of null
假设以下代码连接多个Objects
的content
属性的文本(不含html):
var chapters = Chapters.find({
bookId: this._id
}).fetch();
// => [Object, Object, Object]
var chapterContent = function() {
var results = [];
for (i = 0, len = chapters.length; i < len; i++) {
var chapter = chapters[i];
results.push(chapter.content.replace(/(<([^>]+)>)/ig, ""));
}
return results;
});
// => ["srtrt", "fffff", "ggggg"]
var chapterContentWords = chapterContent.join(" ");
// => srtrt fffff ggggg
var chapterContentWordsNumber = chapterContentWords.match(/['w-]+/g).length;
但是在最后一部分(它应该返回单词数)中,我得到了以下错误:
队列任务异常:TypeError: Cannot read property 'length' of空
我做错了什么?
要获取单词数,可以这样做:
var chapterContentWordsNumber = chapterContentWords.split(" ").length;
或简单的:
var chapterContentWordsNumber = chapterContent.length;
相关文章:
- 无法读取property 'length'在旁边的未定义的
- 无法读取property 'length'vt .扩展;扩展;
- 未捕获的TypeError: Cannot read property 'length'在示例d3代码中
- 无法读取property 'length'在json中使用游标时未定义
- 未捕获的TypeError: Cannot read property 'length'零
- 无法读取property 'length'未定义的(使用geoserver打印地图)
- 无法读取property 'length'在For循环(jQuery)中未定义
- 无法读取property 'length'未定义的将数组从节点发送到翡翠
- 未捕获的TypeError: Cannot read property 'length'使用setInt
- 无法读取property 'length'Node.js &玉
- 无法读取property 'length'属性未定义的
- 无法读取property 'length'null (javascript)
- 未捕获的TypeError: Cannot read property 'length'简单JSON数组
- JQuery Datatable Error “Cannot read property length of undef
- 在“I"”TypeError: Cannot read property 'length'的定
- 队列任务异常:TypeError: Cannot read property 'length'零
- 未捕获的TypeError: Cannot read property 'length'的定义
- Jquery错误:无法读取property 'length'的定义
- 无法读取property 'length'null"RegEx的结果
- 无法读取property 'length'使用CSS显示块(select/onchange)