javascript - jquery parses json as array and object at the same time -


i have simple json string generated php json_encode() function().

   array(3) {   [38105]=>   array(3) {     [0]=>     array(10) {       ["value_id"]=>       string(5) "29428"     }     [1]=>     array(10) {       ["value_id"]=>       string(5) "79332"     }     [2]=>     array(10) {       ["value_id"]=>       string(5) "41199"     }   }   [38110]=>   array(3) {     [3]=>     array(10) {       ["value_id"]=>       string(5) "29429"     }     [4]=>     array(10) {       ["value_id"]=>       string(5) "79333"     }     [5]=>     array(10) {       ["value_id"]=>       string(5) "41201"     }   }   [38115]=>   array(3) {     [6]=>     array(10) {       ["value_id"]=>       string(5) "29430"     }     [7]=>     array(10) {       ["value_id"]=>       string(5) "79334"     }     [8]=>     array(10) {       ["value_id"]=>       string(5) "79334"     }   } } 

in template php output:

<script type="text/javascript">     var productmediagallery = <?php echo json_encode($block->getrelatedproductsgalleryimages()); ?>; </script> 

the problem function interprets first set array, , rest objects, can't first item of set.

function createzoomoverlay() {     if (typeof productmediagallery !== 'undefined') {          $.each(productmediagallery, function(key,value) {             console.log(value);         });     } } 

chrome console output

[object, object, object] object {3: object, 4: object, 5: object} object {6: object, 7: object, 8: object} 


Comments