I have a problem if this optional array is empty:
<script>
var parsedArray = JSON.parse('<?php echo json_encode($myArray); ?>');
console.log(parsedArray );
</script>
All is fine if array is NOT empty, but the problem comes if there are no values in array;
Uncaught SyntaxError: Unexpected token A in JSON at position 0
Console.log just spits Array out if array is empty.
I want to learn how is this done properly. How to pass an empty array to jQuery so I can run myArray.length function on it for example and so that it returns 0 if it is empty.
$myArrayis an emptyarray()json_encode should return[]so I'm not sure where the syntax error is coming from. What does the response fromjson_encode($myArray);look like if empty or rather what is$myArraylooking like?Array