Reference JavaScript reference

String.prototype.endsWith 参考

String.prototype.endsWith Reference,整理语法、参数、示例、返回值和常见错误,适合快速查询 JavaScript 写法。

语法

js
const result = text.endsWith("value");

参数

  • searchString:要查找、匹配或处理的字符串。
  • position:可选,从哪个位置开始处理。

返回值

返回布尔值。

示例

js
const text = "caijiao reference";
const result = text.endsWith("reference");
console.log(result);

常见错误

  • 在 null 或 undefined 上调用实例方法会抛出 TypeError。
  • 正则没有设置合适的 flags 时,可能只匹配到第一个结果或大小写不符合预期。

相关内容