如何从控制台访问数组的主题

I Can print Object/Arrays from php into Console and than access its sub objects.

For example I've some array in php

<?php 
    $arr = Array('name'=>'sajjad','age'=>'20','sex'=>'m');
    $json = json_encode($arr);
?>
<script>
    console.log(<?php echo $json; ?>);
</script>

I will get following lines as object in chrome console.log.

Object {name: "sajjad", age: "20", sex: "m"}

Suppose i'm not working on backend, how can i access to the subobjects of this object in chrome console panel. like..

For example if I type

>object.name

( and hit enter , console should return me)
>sajjad

or If I type in console

   >object.age
   >20

or

   >object.sex
   >m

Thanks ... For understanding. please see pic one. what i want. enter image description here

I've found the solution. I searched but couldn't find. But a little hit and try helped.

Problem:

enter image description here

Solution 1.

enter image description here

2.

enter image description here

3.

enter image description here

I hope somebody else do need this solution. :)

Just assign that json encoded array into script variable and console log object elements using index, like below:

<?php 
$arr = Array('name'=>'sajjad','age'=>'20','sex'=>'m');
$json = json_encode($arr);
?>
<script>
var obj = <?php echo $json; ?>;
console.log(obj.name); ///sajjad
console.log(obj.age); ///20
console.log(obj.sex); ///m
</script>