Your outermost array isn't assoc and should work with forEach/map. I assume that list is that outer array?
You can give this a try (it will convert it to proper json)
var list = @json($tablat);
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello,
I need convert my array php on array JS, but i dont know do that, because is associatif array :
array:2 [▼
0 => array:2 [▼
"lat" => 48.2833
"longi" => 6.95
]
1 => array:2 [▼
"lat" => 48.2888
"longi" => 6.98
]
]
When its simple array i do that:
var list = <?=$tablat;?>;
list.forEach(
element => L.marker([element, 6.95]).addTo(macarte)
);
But that dont work for associatif array, maybe laravel give method for ? i dont find so i tell your help
Ty
Ok it might be reading it as a string
Try this
JSON.parse(list).forEach( element => L.marker([element.lat, element.longi]).addTo(macarte))
Please or to participate in this conversation.