简体   繁体   中英

else condition is getting true before if condition

Here is my javascript code. Initially, the else coding is being true before if the condition becomes true.

for(m=0;m<object[l].get("name").length;m++){
  if(object[l].get("name")[m]==userName){
    valid(userName);
  } else {
    notValid(userName);
  }
}

If userName is not equal with object[l].get("name")[m] , then else part will execute. If first object name matches with userName (means object[l].get("name")[0] matched with userName ) then if block will execute first

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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