Reputation: 58810
I have a PHP array dd($iperfProfiles);
array:1 [▼
0 => "ipv6-udp-upload"
]
Trying to access it in JS
I've tried
var iperfProfiles = "{{ json_encode($iperfProfiles) }}";
console.log(iperfProfiles);
return false;
I get
IPERF:1699 ["ipv6-udp-upload"]
How do I basically turn a PHP array into a JS array ?
Upvotes: 0
Views: 81
Reputation: 684
//in PHP
$iperfProfiles = json_encode($iperfProfiles);
//and then in JS
var iperfProfiles = JSON.parse({!!$iperfProfiles!!});
Upvotes: 1
Reputation: 104
try with just removing quotes
var iperfProfiles = {{ json_encode($iperfProfiles) }};
console.log(iperfProfiles);
Upvotes: 1
Reputation: 11
just use @json blade directive and pass raw php data to it without encoding it JSON.
in blade template:
const profiles = "@json($profiles)"
Upvotes: 1