Skip to content Skip to sidebar Skip to footer

Laravel Javascript Passing An Array From Backend To A Array In Javascript

I have a controller that passes a array to the blade file call it $data From there I echo the data to the page via blade like {{ $data[0]['name] }} The problem is I also want the d

Solution 1:

So in doing this, you'd simply pass the data to javascript the same way you would with php: <script> var a = ['{{$data[0]['name] }}','{{$data[0]['name] }}'];</script>

Or, if you don't want to go through each individual one and add them by hand, use laravels built in foreach loop:

var a = [@foreach($dataas$k => $info)
   '{{ $info }}',
@endforeach ]

This just depends on exactly how you plan on going about this

Post a Comment for "Laravel Javascript Passing An Array From Backend To A Array In Javascript"