javascript - 如何将 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);
解决方案
"J" == "j"
上述陈述将被评估为 False。两者resultA
和resultB
以下都将为真。
const str = 'John';
let resultA = str.startsWith('J');
let resultB = str.toLowerCase().startsWith('j');
console.log(resultA);
console.log(resultB);
推荐阅读
- reactjs - reactjs中如何将对象转换为字符串
- excel - 如何利用右键功能选择表格中的多个单元格进行计算?
- java - 如何使用 Streamingout 返回 206 响应
- c - getaddrinfo 忽略尾随数据?
- java - 是否可以使用字符串解析字符串来捕获两种不同的时间格式?
- firebase - google cloud pub/sub -> 在 firebase 函数上发布
- git - 跨 3 个环境的 GitFlow
- codeigniter - 使用codeigniter发送电子邮件时出错?
- php - 从 Laravel 的另一个表中的 Id 为 json 格式的表中选择值
- reporting-services - 添加 LookupSet 值的总计