-1
    var people = [
  { firstname : 'n1', lastname: 'ln1', age: 32, hasSmartphone: false }, 
  { firstname : 'n2', lastname: 'ln2', age: 40, hasSmartphone: true },
  { firstname : 'n3', lastname: 'ln3', age: 81, hasSmartphone: true },
  { firstname : 'n4', lastname: 'ln4', age: 40, hasSmartphone: false } 
                 ];

How can i get access to Objects in Array. I need access to firstName values ('n1' ... 'n4') and hasSmartphone values (true or false)? Thanks.

asd dsas
  • 3
  • 1

2 Answers2

2
for (var i=0;i<people.length;i++) {
  var person = people[i];
  var firstName=person.firstname;
  var sm = person.hasSmartphone;
  ...
}
mplungjan
  • 169,008
  • 28
  • 173
  • 236
0

Examples of accessing.

The first firstName:

people[0].firstName < the firstName property of this first object
      ^^
  first object
  in your array

Or hasSmartphone of the third object:

people[2].hasSmartphone < the hasSmartphone property of this third object
      ^^
  third object
  in your array
nicael
  • 18,550
  • 13
  • 57
  • 90