Home > OS >  how to combine 2 object in json array and give comma?
how to combine 2 object in json array and give comma?

Time:10-13

hi i need help to write a format code. i write javascript code to parse json and use the data, the json file contain latitude and longtitude data :

const api_url = 'json.php'
async function getjsonlatest() {
    const response = await fetch(api_url);
    const data = await response.json();

i can grab data from array [0]

const api_url = 'json.php'
async function getjsonlatest() {
    const response = await fetch(api_url);
    const data = await response.json();
    const latitude = (data[0].latitude)
    const longitude = (data[0].longtitude)
    console.log(latitude)
    console.log(longitude)
           

the console.log result is (line 1) -7.247100 (line 2) 112.775340

i need to format like this [latitude,longitude] to fill this code :

marker.setLatLng([latitude, longtitude]);

how can achieve that?

CodePudding user response:

You dont need to worry about the comma.

marker.setLatLng([latitude, longtitude]);

this code is already functional and will call setLatLng() with an array arg containing latitude and longitude

  • Related