Leaflet latlng help please

I have below key, value pairs of object.

let stores = [{
    "recommendation": {},
    "storeNumber": "5758-13907",
    "id": "15051",
    "name": "La Cienega & Gregory Way",
    "phoneNumber": "310-659-9562",
    "coordinates": {
        "latitude": 34.063584,
        "longitude": -118.376354
    }......

I am trying to iterate through to get all [cordinates][latitude] and [cordinates][longtitude] with leaflet API and have the following code.

 for(var [index, store] of stores.entries()) {
        var latlng = new L.marker( store["coordinates"]["latitude"],
       store["coordinates"]["longitude"]);

but all the time latlng varaible is null. how to get latlng value using leaftlet API please

Hello there,

I have move this into a more suitable sub-forum.

To answer your question: I believe L.marker is expecting the first argument to be an array, where arr[0] is the latitude, and arr[1] is the longitude.

On a side note, are you using the index anywhere in your code?

Hope this helps

Hi, Thanks for the help. when I use, code like

for(var [index, store] of stores.entries()) {
       lon = store["coordinates"]["latitude"];
       lat = store["coordinates"]["longitude"];
 var latlng = new L.marker(lon,lat);

the lon and lag has correponding values but still the latlng value is null.

and yes, i am using the indx somewhere in code.

What I suspect you need is:

L.marker([lon,lat]);

Thank you, that fixed it!