首页 > 解决方案 > javascript过滤字符串数组,匹配不区分大小写的子字符串

问题描述

我有一个由某个字符串过滤的名称数组。如何匹配包含此字符串但不区分大小写的所有名称?

this.employeeDisplayList = this.employeeList.filter(e => e.employeeName.includes(this.searchStr));

标签: javascript

解决方案


this.employeeDisplayList = this.employeeList.filter(e => {
    const emp = e.employeeName.toLowerCase();
    const str = this.searchStr.toLowerCase();
    return emp.includes(str);
});

推荐阅读