可以使用字符串的startsWith()方法来判断一个字符串是否以另一个字符串开头。

例如:

let str = "Hello world";
if (str.startsWith("Hello")) {
  console.log("字符串以 Hello 开头");
}

输出结果为:"字符串以 Hello 开头"。

js判断字符开头

原文地址: https://www.cveoy.top/t/topic/5rS 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录