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 6377389
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:51:57+00:00 2026-05-25T01:51:57+00:00

Maybe I’ve just been staring at this screen for too long, but I cannot

  • 0

Maybe I’ve just been staring at this screen for too long, but I cannot seem to work out why this for loop is hanging?

var not = '3,7';
var nots = not.split(',');
alert(nots.length);
for (var i = 0; i <= nots.length; i++) { 
    nots[i] = parseInt(nots[i], 10);
}
document.write(nots);

Thanks for any help.

Cheers
Charlie

  • 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-05-25T01:51:57+00:00Added an answer on May 25, 2026 at 1:51 am

    In the loop you are testing if i <= nots.length. You should be testing if i < nots.length.

    When the length is 5, there will elements at indexes 0, 1, 2, 3, 4. So when i reaches 5, there are no more elements. But then you set nots[i] (element 5) and extend the array by one. So each time the loop executes when i is equal to nots.length, you are extending the array by one, and so the loop runs “just one more time” only to extend the array further.

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

Sidebar

Related Questions

Maybe I'm just thinking about this too hard, but I'm having a problem figuring
Maybe I am just forgetting something, but I cannot seem to get NUnit to
Maybe this cannot be done, but please help or suggest how this can be
Maybe it's just me, but I cannot understand the documentation regarding Junit test integration
maybe this might be a simple problem but after a long while at Google
Maybe this is just obvious to everyone but can someone explain where XOR (or
maybe this question is a little too general but maybe someone has experience the
Maybe this has already been answered and I am searching incorrectly, but here is
Maybe this is a really dumb question, but please hear me out. I have
Maybe I am not from this planet, but it would seem to me that

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.