可以使用 JavaScript 中的字符串方法 startsWith() 来判断一段文本是否以 # 开头。

const text = 'Hello, world!';

if (text.startsWith('#')) {
  console.log('The text starts with #');
} else {
  console.log('The text does not start with #');
}

如果 text 以 # 开头,则输出 'The text starts with #',否则输出 'The text does not start with #'。

JavaScript 判断文本是否以 # 开头

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

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