0

I have a PHP array

$logEnabled = explode(',',$baby->logEnabled);
// dd($logEnabled);

result

array:3 [▼
  0 => "pee"
  1 => " poop"
  2 => " feed"
]

I'm trying to pass that to JS , I did this

console.log({{json_encode($logEnabled) }});

I kept getting

["pee"," poop"," feed"]

I want to see [pee,poop,feed]

Any hints for me

code-8
  • 54,650
  • 106
  • 352
  • 604

2 Answers2

-1

You can try

$logEnabled = "[".$baby.logEnabled."]"

Now, $logEnabled contains the JS array.

Nice Books
  • 1,675
  • 2
  • 17
  • 21
-1

Try this I'm sure this will work

var app = @json($logEnabled);

Jay Patel
  • 1,098
  • 7
  • 22