gpt4 book ai didi

javascript - 排队任务中出现异常 : TypeError: Cannot read property 'length' of null

转载 作者:行者123 更新时间:2023-12-03 12:32:47 25 4
gpt4 key购买 nike

下面的代码假设连接许多对象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;

但是在最后一部分(它应该返回单词数),我收到以下错误:

Exception in queued task: TypeError: Cannot read property 'length' of null

我做错了什么?

最佳答案

要获取单词数,您可以执行以下操作:

var chapterContentWordsNumber = chapterContentWords.split(" ").length;

或者简单地说:

var chapterContentWordsNumber = chapterContent.length; 

关于javascript - 排队任务中出现异常 : TypeError: Cannot read property 'length' of null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23855324/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com