Iterating over array of strings produces error

前端 未结 4 1304
太阳男子
太阳男子 2021-01-26 13:22

I pass in an array of error messages to parse. An example input would be:

\"An item with this x Id already exists.
 An item with this y id already exists.
 An it         


        
4条回答
  •  佛祖请我去吃肉
    2021-01-26 14:09

    You are getting Error! in end because the splitting is giving you empty line "" and when you check for it with if(!aLines[i]) it returns true because it is empty/null/nothing. You can check it here in a fiddle, you remove the empty line from end and it does not go over array 4 times.

    I have also put in following code which shows alert:

        var a="";
        if(!a){
            alert("!a");
        }
    

提交回复
热议问题