我有一个数据对象,其中包含一些数据,现在我想创建另一个名为 mapdata2
的对象,其结构与数据相同。但是我的代码没有运行成功,而且还显示了一些语法错误。
我已经创建了 mapdata2
对象并在其中创建了一个空的 features 数组。
它显示了一个错误:
TypeError: i.features is undefined
<script>
data = {"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties":
{
"title": "ABC", "startDate": 1100, "endDate": 1200, "latitude": 60.814, "longitude": 11.845, "content": "content."
},
"geometry":
{
"type": "Point","coordinates": [ 60.814, 11.845, 1]
}
},
{
"type": "Feature",
"properties":
{
"title": "XYZ", "startDate": 1100, "endDate": 1200, "latitude": 40.814, "longitude": 15.845, "content": "content."
},
"geometry":
{
"type": "Point","coordinates": [ 40.814, 15.845, 1]
}
},
]
}
mapdata2 = {
"type": "FeatureCollection",
"features" : []
};
for(i in data){
console.log(i);
mapdata2.features.push({
type:"Feature",
properties : { title: i.features.properties.title, startDate: i.features.properties.startDate, endDate: i.features.properties.endDate latitude: i.features.properties.latitude, longitude: i.features.properties.longitude, content: i.features.properties.content },
geometry : { type: "Point", coordinates: i.features.geometry.coordinates }
})
}
console.log(mapdata2);
</script>
push
。例如:mapdata2.features[0].geometry.coordinates.push(777);
- Omri Attiya