Populating an array of objects in javascript

javascript

Solution

A very short answer:

airports.push(new Airport("code","city"));

Problem

Let us say I have an object Airport with members airportCode and airportCity like this: ``` function Airport(airportCode, airportCity) { this.airportCode = airportCode; this.airportCity = airportCity; }; ``` How can I create an array of objects Airport to which I can add. In Java, this would work like this: ``` while(st.hasMoreTokens()) { Airport a = new Airport(); a.airportCode = st.nextToken(); a.airportCity = st.nextToken(); airports.add(a); } ```

Original source