javascript - how to push arrays in array and NOT concatenate? -


i have following php code gives array variable called "markers".

window.markers = [];  <?php if( have_rows('actin_center') ): ?> <?php while( have_rows('actin_center') ): the_row(); ?>  window.markers.push( [ ['<?php the_sub_field('center_name'); ?>', '<?php the_sub_field('center_address'); ?>', <?php the_sub_field('latitude'); ?>, <?php the_sub_field('longitude'); ?>] ] );  <?php endwhile; ?> <?php endif; ?> 

this works fine far yet returns array (on alert) as:

cool center 1,rewitz gofella, 1234 lorem,50,50,cool center 2,lorem ipsum, 1234 quosque,60,60,cool center 3,veniat elaborat, 1234 ipsum,70,70

what need, yet, following form keeping arrays (of sub_fields) inside array , not concatenate them. as:

var markers = [     ['first center','first address',50,50],     ['second center','second address', -25.363882,131.044922],     ['third center','third address', 10.363882,95],     ['fourth center','fourth address', -50,-90],     ['fifth center','fifth address', 30,5], ]; 

as can see in code above tried simple double bracket [[ ]] doesn’t work. how done correctly? help.

ps: if feels urged down vote question, please kind let me know why may learn something.

due comments:
alert( [[1,2][3,4]] ) popup wrong 1,2,3,4
alert( json.stringify([[1,2][3,4]]) popup [[1,2],[3,4]]

.push([1,2]) add array markers: [[1,2],[3,4],[5,6]]
.push(1,2) add elements markers: [1,2,3,4,5,6]

better way, don't execute javascript .push (save client cpu time)
define array in javascript in way:

window.markers = [ <?php while( have_rows('actin_center') ): the_row(); ?>   ["<?php the_sub_field('center_name');?>","<?php the_sub_field('center_address'); ?>",<?php the_sub_field('latitude');?>, <?php the_sub_field('longitude');?>], <?php endwhile; ?> ]; 

result should looks this

window.markers = [ ['first center', 'first address', 50, 50], ['second center','second address',-25.363882, 131.044922], [... ,... , ... ,...], ]; 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -