这就是我按标题值过滤一些数据
的方式:
data.filter(x => x.title.includes(term))
这样的数据
Sample one
Sample Two
Bla two
将被“减少”为
Bla two
如果我按两个
过滤。
但是我需要得到过滤后的结果
Sample Two
Bla two
最佳答案
您可以使用不区分大小写的正则表达式:
// Note that this assumes that you are certain that `term` contains
// no characters that are treated as special characters by a RegExp.
data.filter(x => new RegExp(term, 'i').test(x.title));
也许更简单和更安全的方法是将字符串转换为小写并进行比较:
data.filter(x => x.title.toLowerCase().includes(term.toLowerCase()))
关于javascript - ES6 : Filter data with case insensitive term,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44469548/