javascript (iQuery ) 第一个字母是感叹号
javascript (iQuery ) first letter is exclamation
我要检查的是变量a的第一个字母(!-感叹号)
这里有没有给我的例子?我发现了其他东西,但不是因为第一个字母是感叹号。
非常感谢你回复我
//using regex
let a = "!variable";
let test = /!/.test(a);
if (test) console.log("there is \"!\" somewhere in \"a\" variable");
//or not using regex
let char = a.split("", 1)[0];
if (char == "!") console.log("first letter is \"!\"");
第二部分取第一个字母,如果是“!”则记录消息。 ,第一部分测试整个字符串以找到“!”。我不确定是否有办法检查第一个字母是“!”使用正则表达式。
我要检查的是变量a的第一个字母(!-感叹号) 这里有没有给我的例子?我发现了其他东西,但不是因为第一个字母是感叹号。 非常感谢你回复我
//using regex
let a = "!variable";
let test = /!/.test(a);
if (test) console.log("there is \"!\" somewhere in \"a\" variable");
//or not using regex
let char = a.split("", 1)[0];
if (char == "!") console.log("first letter is \"!\"");
第二部分取第一个字母,如果是“!”则记录消息。 ,第一部分测试整个字符串以找到“!”。我不确定是否有办法检查第一个字母是“!”使用正则表达式。