这是一个有效的 JavaScript 代码。然而,它对我来说看起来多余。有什么办法可以清理掉吗?
let text = 'Some search text';
const searchMatch =
entry.title.toLowerCase().includes(text.toLowerCase()) ||
entry.description.toLowerCase().includes(text.toLowerCase()) ||
entry.keywords.toLowerCase().includes(text.toLowerCase());
return searchMatch;
最佳答案
你可以这样做:
const text = 'Some search text'.toLowerCase();
return [entry.title, entry.description, entry.keywords].some(s => s.toLowerCase().includes(text));
关于javascript - 尝试缩短冗余的 Javascript 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53775451/