0

Here is a part of the tutorial from Codecademy.
The instruction is:
Show the name of each member in the array by "For"

function Personne (nom, age)
{
    this.nom = nom;
    this.age = age;
};

var famille = new Array();
famille[0] = new Personne("alice", 40);
famille[1] = new Personne("bob", 42);
famille[2] = new Personne("michelle", 8);
famille[3] = new Personne("timmy", 6);

for( i=0; i<famille.length; i++)
{
    console.log( famille[i] );
};

Which means I need to show:

alice
bob
michelle
timmy

but with the "For" that I wrote, it shows everything like

{ nom: 'alice', age: 40 }
{ nom: 'bob', age: 42 }
{ nom: 'michelle', age: 8 }
{ nom: 'timmy', age: 6 }

According to the tutorial's instruction, I have to creat the array like that
So what is the correct way to get only the name(nom) of each member?
Thanks for those who can help me!

Jiang Lan
  • 171
  • 1
  • 12
  • Sorry about that, as a rookie and learn by myself, I don't think I can easily find the answer in the link that you show me, that's why I prefer to ask on my own, ps, I am learning in french, so I only know very few term in english. – Jiang Lan Mar 25 '16 at 17:16

1 Answers1

1

Try to access the object's property and print it,

for( i=0; i<famille.length; i++) {
    console.log(famille[i].nom);
};

You are printing the object itself.

Rajaprabhu Aravindasamy
  • 66,513
  • 17
  • 101
  • 130