endsWith JavaScript · 字符串方法
判断字符串是否以指定子串结尾。
怎么用
字符串.endsWith(子串, [字符串长度])
小例子
console.log("hello".endsWith("lo"));
console.log("hello".endsWith("he"));
运行结果
true false
提醒:第二个参数可指定只考虑前 N 个字符。
官方文档:https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith
在代码里遇到不认识的词?打开代码点读机,点一下就懂 → ← JavaScript全部词条