我想在这个例子中使用map而不是for循环。 我有一个包含数据的CSV文件
CSV file
address,type,building,geometry
"This","is","an","example"
"This","is","an","example"
"This","is","an","example"
"This","is","an","example"
"This","is","an","example"
"This","is","an","example"
"This","is","an","example"
var geojsonFeature;
var globalData= data.map(function(d){return JSON.parse(d.geometry);});
var buildingData= data.map(function(d){return JSON.parse(d.type);});
for (i=0;i<globalData.legnth;i++)
{
geojsonFeature = {
"type": "Feature",
"properties": {
"name": buildingData[i]
},
"geometry": {
"type": "MultiPolygon",
"coordinates": globalData[i].coordinates
}
};
listGeoData.push(geojsonFeature)
}
我想用地图替换For-Loop以这种方式获得“listGeoData”。
答案 0 :(得分:0)
这假设listGeoData
在for
循环之前为空。
var listGeoData = globalData.map(function(data,i) {
return {
"type": "Feature",
"properties": {
"name": buildingData[i]
},
"geometry": {
"type": "MultiPolygon",
"coordinates": data.coordinates
}
};
});