You should always JSON-encode data used in the context of JavaScript. This makes the data safe for use, so you don't have to worry about injection or escaping.
<script>
<?php
$myArr = array(1, 2, 3, 4, 5);
$myVar = 'Word!';
echo 'var myArr = ', json_encode($myArr), ';'; // var myArray = [1, 2, 3, 4, 5];
echo 'var myVar = ', json_encode($myVar), ';'; // var myVar = "Word!";
?>
console.log(myArr);
</script>