When I provide an array of error messages to parse, the input example looks like this:
"An item with this x Id already exists.
An item with this y id already exists.
An item with this barcode already exists.
"
The string contains each line separated by a \n character, with an additional \n at the end.
function( msg )
{
alert( "\"" + msg + "\"" );
var aLines = msg.split( /\r?\n+/ );
for ( var i in aLines )
{
if ( !aLines[i] ) { alert( "Error!" ); continue; }
alert( i + ": \"" + aLines[i] + "\"" );
}
}
I split the string into lines and loop through them. When it reaches index 3 and finds no line, it triggers the error alert. Shouldn't that be represented as an empty string? For example, ""
The loop then continues to index 4, displaying the contents of a function.
In total, I receive five alerts:
0: "An item with this x Id already exists."
1: "An item with this y id already exists."
2: "An item with this barcode already exists."
Error!
The last alert is the most perplexing:
hasObject: "function(o) {
var l = this.length + 1;
... more lines ...
}
I'm puzzled by these results. Why does the iteration include one extra element? And why is the final element a function instead of an empty string or another error message? This behavior raises questions about the accuracy of the process.