需要在javascript中将一些值传递到数组中,但仍有困难

需要在javascript中将一些值传递到数组中,但仍有困难,javascript,arrays,Javascript,Arrays,我需要建立一个包含坐标集合的阵列。。该示例显示了这样构建的阵列 stops = [{"Geometry":{"Latitude":51.507937,"Longitude":-0.076188}}, {"Geometry":{"Latitude":51.51168,"Longitude":-0.114155}}, {"Geometry":{"Latitude":51.5010063,"Longitude":-0.041407}}] ; 我正在尝试构建一个循环

我需要建立一个包含坐标集合的阵列。。该示例显示了这样构建的阵列

stops = [{"Geometry":{"Latitude":51.507937,"Longitude":-0.076188}},
         {"Geometry":{"Latitude":51.51168,"Longitude":-0.114155}},
         {"Geometry":{"Latitude":51.5010063,"Longitude":-0.041407}}] ;
我正在尝试构建一个循环,从其他地方读取co ORD并将其推送到stops数组中。。这是我目前所知道的,但我知道这是错的

var x = document.getElementsByClassName("postcode");
for (i = 0; i < x.length; i++) {
    postcode = x[i].innerText;
    lon = getLon(postcode);
    lat = getLat(postcode);

    myarray = [{"Latitude":lon,"Longitude":lat}];

    stops.push([{"Geometry":myarray}]);

}
var x=document.getElementsByClassName(“邮政编码”);
对于(i=0;i
更换

myarray = [{"Latitude":lon,"Longitude":lat}];
stops.push([{"Geometry":myarray}]);

for
循环中添加缺少的
var
关键字:

for (var i = 0; i < x.length; i++) {
for(变量i=0;i

如果不这样做,它会使
i
变量变为全局变量,这通常会导致痛苦的错误。

“但我知道它错了”你怎么知道?怎么了?因为如果我转储数组,它看起来与我在第一段代码中需要的数组完全不同。它看起来如何?
for (var i = 0; i < x.length; i++) {