假设我有一个对象Airport,成员是airportCode和airportCity,如下所示:

function Airport(airportCode, airportCity) {
        this.airportCode = airportCode;
        this.airportCity = airportCity;
    };

如何创建可添加到的对象机场的数组。在Java中,它将像这样工作:
while(st.hasMoreTokens()) {
    Airport a = new Airport();
    a.airportCode = st.nextToken();
    a.airportCity = st.nextToken();
    airports.add(a);
}

最佳答案

一个很简短的答案:

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

09-26 21:57