我正在尝试flat()在Angular ts文件中使用。当我运行项目时,它给出一个错误:[question.determinativeTerms].flat不是函数!我安装了它:
npm install --save array.prototype.flat
function matchUserInputToDeterminativePhrases(
faqs: Question[],
searchPhrase: string
): Question[] {
return faqs.reduce((matches, question) => {
let foundMatch = false;
[question.determinativeTerms].flat().forEach(term => {
if (
!foundMatch &&
searchPhrase &&
searchPhrase
.toLowerCase()
.search(new RegExp(`\\b${term.toLowerCase()}`)) !== -1
) {
foundMatch = true;
matches.push(question);
}
});
return matches.reverse();
}, []);
}
繁星点点滴滴
相关分类