0

My code is like

var persons = [];
function Person(id, name) {
    this.id         = id;
    this.name       = name;
}

When I am trying to loop throught all persons, I'm getting an uncaught TypeError: Cannot read property "name" of undefined.

for (var person in persons) {
   console.log(persons[person]);
}

I noticed that my console is logging all persons and adding an property values after them

[Person, $family: function, $constructor: function, each: function, clone: function, clean: function…]

I'm pretty sure that that the code is breaking after looping the first person.

I'm using jquery-1.11.1.js

Any ideas how to get rid of this error? Thank you in advance.

Hene
  • 159
  • 3
  • 13
  • How are you populating `persons` array? – dfsq Nov 03 '14 at 14:06
  • I think you need to `console.log(person)` in your loop. `person` is an element of your array type `Person`, while `persons` array do not have key like that. – vaso123 Nov 03 '14 at 14:10

0 Answers0