I searched for some methods online, and finally I used the method of using json strings.
Suppose there is a php array $arr, the code is as follows:
The code copy is as follows:
<script> // The default script in html5 is javascript, so there is no need to specify script language
var arr_js = <?php echo json_encode($arr)?>;
</script>