限制字符串的开头或者结尾

使用es6的startsWith和endsWith方法

let str='postedit';
 
if(str.startsWith('po')){
  alert('开头正确');
}else if(str.endsWith('it')){
  alert('结束正确');
}
发布了112 篇原创文章 · 获赞 33 · 访问量 4万+

猜你喜欢

转载自blog.csdn.net/qq_40282732/article/details/104420444