我正在嘗試flat()在Angular ts文件中使用。當(dāng)我運(yùn)行項目時,它給出一個錯誤:[question.determinativeTerms].flat不是函數(shù)!我安裝了它:npm install --save array.prototype.flatfunction 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(); }, []);}
如何在角度項目中使用.flat()?
喵喵時光機(jī)
2021-03-30 13:10:53