Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8725833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:07:43+00:00 2026-06-13T08:07:43+00:00

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

  • 0

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 item with this barcode already exists.
"

That is, the string is literally each line above separated by a \n, with a final \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 it into lines, and iterate over the lines. At index 3 there is no line and the first conditional triggers. Should that not be an empty line? e.g. “”

Then the loop actually goes one more element to 4, and shows a the contents of a function.

That is I get – 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 one is most bizarre:

hasObject: "function(o) {
    var l = this.length + 1;
    ... more lines ...
}

I don’t understand what is happening here. Why is it iterating over one more element? And why is the last element a function? And shouldn’t offset 3 be an empty string? That is I should not be alerting “Error!” here.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T08:07:44+00:00Added an answer on June 13, 2026 at 8:07 am

    Never loop over an array with for…in.

    Iterates over the enumerable properties of an object, in arbitrary order.

    Why is using "for…in" with array iteration a bad idea?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I came across this post pass array to method Java on how to pass
How to pass an array into a SQL Server stored procedure? For example, I
how do i pass php array's to ruby script as an argument so that
I am trying to pass a single array object (that is a nsdictionary of
I'm having a multi-language site and need to pass error messages in different languages
I am trying to pass an array of Student into the function processStudent(string myFilename,
How do I pass array of parameters through Get method in rails? Currently my
Hos do I pass array of Integers as a params to XSLT?
I am trying to pass array parameter to SQL commnd in C# like below,
Hello Sir i am pass array list through url android to php my arraylistvalues[x,y.z,....]

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.