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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:48:30+00:00 2026-05-24T20:48:30+00:00

This is weird. Check this out: for( var i = 0; i <= videos.length;

  • 0

This is weird. Check this out:

 for( var i = 0; i <= videos.length; i ++ ){

    alert(videos[i].id); // this works and alerts the correct number

    var foo = videos[i].id; // firebug says "videos[i] is undefined"

 }

There are 3 videos. In FF this alerts all 3 video id’s then fails saying that videos[i] is undefined. No Idea, at all.

  • 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-24T20:48:31+00:00Added an answer on May 24, 2026 at 8:48 pm

    Get rid of the = in your for loop condition.

    for( var i = 0; i < videos.length; i ++ ){
        ...
    }
    

    With <=, you are iterating to the index, one larger than the actual index value of the Array, so you are iterating over an invalid index which returns undefined.

    For example…

    If you have array('A','B','C'), the length is 3. Now, if you iterate to 3 <= i, and include 0, as arrays begin with in Javascript, you will actually loop 4 times, not three.

    The index value of A is 0, not 1, so you need to stop BEFORE i is equal to the length, not continue until i is equal to the length, since the 0 index is essentially added to the total length for the looping, meaning 3+1. 4 loops over this array would be one too many, hence the < and not <=. You want to STOP before 4, not stop AFTER 4 but before 5.

    Also, it is generally good practice to cache the length of the Array, because some browsers do not optimise it.

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

Sidebar

Related Questions

Just stumbled upon this weird bug with php's DateTime object... Check this out: <?php
I just found out this weird behavior, is this a bug or what am
Check out the weird behavior I'm getting with two strings. I suspect of course,
Brand new to android and facing a weird problem.Check out the code below FirstActivity.java:
this weird thing is happening with my uitableview cell selection style, Instead of changing
Getting this weird LINQ error. title = System.Linq.Enumerable+WhereSelectEnumerableIterator`2[System.Xml.Linq.XElement,System.String Here is the code I have:
I'm getting this weird issue. Basically I'm animating a view with translate animation. (Translate
I had this weird problem a little while ago and haven't been able to
I'm having this WEIRD Xcode error - Uncategorized error. It seems to look for
Could someone please explain this weird phenomenon: http://jsfiddle.net/sPA2V/ For some reason, the box footer

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.