1👍
✅
json_encode
function is good for that.
Any php array you can transfer to json and then echo in the js.
var dataString="<?php echo json_encode($categoriesTest); ?>";
Source:stackexchange.com