PHP string array for javascript string array parsing error

I tried

var name = <?php echo json_encode($eventname); ?>; 

and

 var name = new Array("<?php echo implode('","', $eventName);?>"); 

to parse my array of name strings from PHP to Javascript. It is displayed as

 var name = ["lalalala","Lalala","test"]; 

and

 var name = new Array("lalalala","Lalala","test"); 

in viewsource, but when I tried to use the name [i] to get a string, it returned a character, not a string. The size of the array name is also not 3, but 20 (this is the total number of characters plus three ","). How can i fix this?

+4
source share
1 answer

Pretty accurate, because 'name' points to window.name (Thanks Fabrício Matté ). Look at here

It works great if you change the "name" to "names".

+5
source

Source: https://habr.com/ru/post/1478919/


All Articles