php - Convert json to array in jquery -
i'm trying convert json object array. i've saw many questions on didn't me. my php code : $arr = array ( [1] => 10 [5] => 20 ) //array key random i want assign above array jquery variable. jquery code : var obj = '<?php echo json_encode($arr)?>'; when print obj gives me {"1":"10","5":"20"} . want result in array [1:10,5:20]. and after want access array values key (e.g. obj[1] or obj[5] ) ignore syntax error. thanks. you need define var obj without usage of ' in script <script> var obj = <?php echo json_encode($arr)?>; alert(obj[1]);// alert 10 </script>