I am working on a client-server project. As I writing the script in HTML. I have a hard time push the data I have to array. Here is the source code snippets:
var latitude = [];
async function getapi(url){
const response = await fetch(url);
var data = await response.json();
show(data);
return data;
}
getapi(api_url);
function show(data){
for (r in data){
latitude.push(data[r]['DepLat'];
var dep_marker = new mapboxgl.Marker({color: 'red'})
.setLngLat([data[r]['DepLng'],data[r]['DepLat']])
.addTo(map);
var arr_marker = new mapboxgl.Marker({color: 'cyan'})
.setLngLat([data[r]['ArrLng'],data[r]['ArrLat']])
.addTo(map);
}
}
The result I have in latitude after calling show(data) is still empty. Thank you.
datalook like?await.