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

  • Home
  • SEARCH
  • 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 8245653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T22:15:12+00:00 2026-06-07T22:15:12+00:00

var names = [Ringo, John, Paul, George]; for (var i = 0; i <

  • 0
var names = ["Ringo", "John", "Paul", "George"];

for (var i = 0; i < names.length; i++) {
    alert("Say hello to " + names[i]);
}

In the code above, I assume it’s the last piece (names[i]) that’s making the index of the array change to give me the correct name. Is this true? What exactly is going on? What’s making the index change so that it will change the name? And if I were to use another label for the variable, say ‘a’, or ‘b’ or even ‘counter’, instead of ‘i’, would it still work?

  • 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-07T22:15:14+00:00Added an answer on June 7, 2026 at 10:15 pm

    The first part
    var names = ["Ringo", "John", "Paul", "George"];
    is your array definition. You are loading a JavaScript array with 4 items. Their indices in the array are as follows:

    0 = "Ringo"
    1 = "John"
    2 = "Paul"
    3 = "George"
    

    To refer to those items individually in JS, you would do this:

    var nameOne = names[0]; //nameOne = "Ringo"
    var nameTwo = names[1]; //nameTwo = "John"
    

    The for loop in your code steps through each item in the array. var i = 0 says that we’re creating a new variable to use as the index of the array. This could just as easily be var a, var b, var indexOfTheArray. Whatever.

    The next part i < names.length is a condition that causes the for loop to repeat until it is met. In this case it says “loop as long as the value of i is less than the length of the array names“. array.length gives the total number of items in the array. So names.length would equal 4.

    The last part is a special JS command i++. This says “add 1 to the value of i“.

    Everytime the for loop reaches the closing bracket, it increments i, and evaluates the condition.

    Inside the loop, i represents the current index of the array that you’re working with.

    You can use names[i] as many times as you want in the for loop and it will not change until the next time you reach the end bracket and it loops back around. Then i will increment and you’ll have the next value in the array.

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

Sidebar

Related Questions

say I have a list of names var names = new List<string>{Tom, Dick, Harry};
Using the C# compilers query comprehension features, you can write code like: var names
var names = new[] { new { Name = John, Age = 44 },
I have the following code: var htmlname=''; var names = result.names $.each(names, function( i,
I have an array of names: var names = ['john', 'ted', 'pam']; in the
I'm using the jquery autocomplete UI widget, for example: var names = [John, Jack,
How can i concatenate var names to declare new vars in javascript?: var foo
While reading a book about JavaScript I stumbled across an example: var names =
var name = 'Mike'; var person = { name: 'John', welcome: function(){ var name
I have this code here: var Person = (function() { var name; var PersonConstructor

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.