javascript完成解决方案如果传入的第一个参数字符串以第二个参数也是字符串结束则返回true。
以下是JavaScript代码实现:
function endsWith(str, suffix) {
return str.endsWith(suffix);
}
// 测试代码
console.log(endsWith("hello world", "world")); // true
console.log(endsWith("hello world", "hello")); // false
使用JavaScript内置的字符串方法endsWith()可以方便地实现这个功能。endsWith()方法返回一个布尔值,表示当前字符串是否以指定字符串结尾。如果是,返回true,否则返回false。
原文地址: https://www.cveoy.top/t/topic/794 著作权归作者所有。请勿转载和采集!