简体   繁体   English

如果语句 Javascript 拆分 function 不起作用

[英]split function not working in if statment Javascript

var text = "Q!123"; //Setting variable
if(isNaN(text.split('')[text.indexOf("!") + 1]) != true){ //Checking if character after the ! is a number
    return true; //Return true if true
}else{
    return false; //Return false if false
}

At the if statment where I have text.split(''), im not able to use it whilst grabbing a character from the array在我有 text.split('') 的 if 语句中,我无法在从数组中抓取一个字符时使用它

you write this match statement in if to check after '!'您在 if 中编写此匹配语句以在“!”之后进行检查is number or not是不是数字

 var text = "Q;123". let match = text[text.indexOf(".") + 1].match(/[0-9]/) console.log(match)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM