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

<h1>JavaScript 字符串</h1>

<h2>startsWith() 方法</h2>

<p>如果字符串以指定字符串开头,startsWith() 返回 true:</p>

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

<p>Internet Explorer 11(或更早版本)不支持 startsWith()。</p>

<script>
let text = "Hello world, welcome to the universe.";
let result = text.startsWith("world", 7);

document.getElementById("demo").innerHTML = result;
</script>

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