Skip to main content
formatted the code
Source Link
kzidane
  • 17.7k
  • 3
  • 28
  • 100

In populate()populate() function of service.jsservice.js, I was trying to build an object array to store the passengers' namename, househouse, placemarkplacemark and markermarker. Basically, I created a global array, say database[]database[], then when iterating through every passenger's information in PASSENGERS[]PASSENGERS[],I add both the property and value dynamically:

    database[i].name = PASSENGERS[i].name;
    database[i].house = PASSENGERS[i].house;
    database[i].placemark = placemark;
    database[i].marker = marker;

When I validate the code using 'Inspect Elements' on Google, it pops out the message: Uncaught TypeError:Cannot set property 'name' of undefined.

Uncaught TypeError:Cannot set property 'name' of undefined. 

Is that the correct way to declare an object array? Or is there anything wrong with adding new property and values? Much appreciated.

In populate() function of service.js, I was trying to build an object array to store the passengers' name, house, placemark and marker. Basically, I created a global array, say database[], then when iterating through every passenger's information in PASSENGERS[],I add both the property and value dynamically:

    database[i].name = PASSENGERS[i].name;
    database[i].house = PASSENGERS[i].house;
    database[i].placemark = placemark;
    database[i].marker = marker;

When I validate the code using 'Inspect Elements' on Google, it pops out the message: Uncaught TypeError:Cannot set property 'name' of undefined.

Is that the correct way to declare an object array? Or is there anything wrong with adding new property and values? Much appreciated.

In populate() function of service.js, I was trying to build an object array to store the passengers' name, house, placemark and marker. Basically, I created a global array, say database[], then when iterating through every passenger's information in PASSENGERS[],I add both the property and value dynamically:

    database[i].name = PASSENGERS[i].name;
    database[i].house = PASSENGERS[i].house;
    database[i].placemark = placemark;
    database[i].marker = marker;

When I validate the code using 'Inspect Elements' on Google, it pops out the message:

Uncaught TypeError:Cannot set property 'name' of undefined. 

Is that the correct way to declare an object array? Or is there anything wrong with adding new property and values? Much appreciated.

Source Link
Shun
  • 123
  • 3

PSET8 Can't add property to the object array

In populate() function of service.js, I was trying to build an object array to store the passengers' name, house, placemark and marker. Basically, I created a global array, say database[], then when iterating through every passenger's information in PASSENGERS[],I add both the property and value dynamically:

    database[i].name = PASSENGERS[i].name;
    database[i].house = PASSENGERS[i].house;
    database[i].placemark = placemark;
    database[i].marker = marker;

When I validate the code using 'Inspect Elements' on Google, it pops out the message: Uncaught TypeError:Cannot set property 'name' of undefined.

Is that the correct way to declare an object array? Or is there anything wrong with adding new property and values? Much appreciated.