I am trying to pass a multidimensional array from php(values inserted dynamically in real scenario) to javascript and later those values are used inside the javascript, when I am trying to print the same using loop, the values are not getting printed, when I have checked the array[0].length it is shown undefined
Values getting printed when used with static indexes.
PFB image for reference -

Could anyone please correct me where's my mistake, I have been trying to figure this out from long time, unable to get it to work. Any help is appreciated. Thanks.
<?php
// PHP array
$myArray = array();
$myArray[] = array("id" => 1, "data" => 45);
$myArray[] = array("id" => 3, "data" => 54);
$myArray[] = array("id" => 2, "data" => 69);
$json = json_encode($myArray);
echo $json;
?>
<script type='text/javascript'>
// pass PHP array to JavaScript
var books = <?php echo json_encode($myArray, JSON_PRETTY_PRINT) ?>;
// how to access
for (var i=0;i<books.length;i++){
for (var j=0;j<Object.keys(books[i]).length;j++){
document.write("In Loop: "+books[i][j]);
}
}
console.log("Books length: "+books.length+"\n");
console.log("Books[0] length: "+books[0].length+"\n");
console.log("Out Loop: "+books[0]["id"]+"\n");
console.log("Out Loop: "+books[0]["data"]+"\n");
console.log("Out Loop: "+books[1]["id"]+"\n");
console.log("Out Loop: "+books[1]["data"]+"\n");
console.log("Out Loop: "+books[2]["id"]+"\n");
console.log("Out Loop: "+books[2]["data"]+"\n");
</script>
Object.keys(books[0]).length