首页 > 解决方案 > 如何将 String.prototype.startsWith 过滤器与 html 表一起使用

问题描述

如何在 HTML 表格中使用 String.prototype.startsWith 过滤器

这是我的项目使用 json 的示例,但我必须在我的项目中使用过滤器数组。

http://jsfiddle.net/8kkg3/3471/

这是我想在表格中使用的过滤器代码。

if (typeof String.prototype.startsWith != 'function') {
            String.prototype.startsWith = function (str) {
                return this.substring(0, str.length) === str;
            }
        };
        const str ='John';
        let result =str.startsWith('j');
        console.log(result);

标签: javascriptarrayshtmlfilter

解决方案


"J" == "j"

上述陈述将被评估为 False。两者resultAresultB以下都将为真。

const str = 'John';
let resultA = str.startsWith('J');
let resultB = str.toLowerCase().startsWith('j');

console.log(resultA);
console.log(resultB);

推荐阅读