我已经从csv文件中创建了一个对象数组,所以:
var s=[];
d3.csv('income.csv', function(data) {
data.forEach(function(d, i) {
w={};
w.geoID= data[i]['GEO.id2'];
w.population = data[i]['HC01_EST_VC15'];
s.push(w);
})
})
console.log(s);
console.log(s[1].geoID);
console.log(s)显示:
[]
0: Object { geoID: "Id2", population: "Households; Estimate; Mean income (dollars)" }
1: Object { geoID: "37001", population: "59084" }
2: Object { geoID: "37003", population: "52750" }
3: Object { geoID: "37005", population: "47715" }
4: Object { geoID: "37007", population: "45101" }
5: Object { geoID: "37009", population: "50702" }
6: Object { geoID: "37011", population: "56130" }
但是,console.log(s [1] .geoID)显示:
undefined
什么给出 - 我不仅仅是在这个名为's'的数组的索引1中调用geoID键吗?