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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T21:34:11+00:00 2026-06-16T21:34:11+00:00

Here is the code: // The Person constructor function Person(name, age) { this.name =

  • 0

Here is the code:

// The Person constructor
function Person(name, age) {
    this.name = name;
    this.age = age;
}

// Now we can make an array of peoples
var family = new Array();
family[0] = Person("alice", 40);
family[1] = Person("bob", 42);
family[2] = Person("michelle", 8);
family[3] = Person("timmy", 6);

// loop through our new array
for ( i=0; i < family.length; i++; ) {
    console.log(family[i].name)
};

The expected output of this script is:

alice
bob
michelle
timmy

But the output is:

Uncaught TypeError: Cannot read property ‘name’ of undefined (anonymous function)

  • 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-16T21:34:12+00:00Added an answer on June 16, 2026 at 9:34 pm

    Add a new keyword for each Person added, and remove the extra ; in the for-loop (after the i++)

    // Now we can make an array of people
    var family = new Array();
    family[0] = new Person("alice", 40);
    family[1] = new Person("bob", 42);
    family[2] = new Person("michelle", 8);
    family[3] = new Person("timmy", 6);
    
    // loop through our new array
    for ( i=0; i < family.length; i++ ) {
        console.log(family[i].name);       // Also, added a semicolon here. Not required, but it's good practice to close your lines.
    };
    

    This will now log:

    alice
    bob
    michelle
    timmy

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

Sidebar

Related Questions

I have this code here: var Person = (function() { var name; var PersonConstructor
Here is some code: class Person def initialize(age) @age = age end def age
var Person = function(){}; function klass() { initialize = function(name) { // Protected variables
For instance, take this piece of code: var person = new Person(); or for
Here is my code @Entity class Parent extends Person { @OneToMany(cascade = CascadeType.ALL, fetch
All my code is here,quite simple,and I don't konw where it goes wrong. Person
Ok the error is showing up somewhere in this here code if($error==false) { $query
So, I'm using the XSLT plugin for JQuery, and here's my code: function AddPlotcardEventHandlers(){
I have a problem using QBE with NHibernate. Here's a sample code: Person person
I found this code online where the person is instantiating a class which has

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.