代码示例:(标识:js_endswith_1)
<!DOCTYPE html>
<html>
<body>

<h2>JavaScript 字符串</h2>

<p>检查字符串是否以 "Gates" 结尾:</p>

<p id="demo"></p>

<p>Internet Explorer 不支持 endsWith() 方法。</p>

<script>
let text = "Bill Gates";
document.getElementById("demo").innerHTML = text.endsWith("Gates");
</script>

</body>
</html>
运行结果: