I have a data object which has some data now i want to create another object mapdata2 which has same structure as data. but my code did not work and also shows some syntax error.
I have created mapdata2 object and empty features array inside it.
It shows an error:
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>