javascript - Creating many random arrays for use as elements in another array -


consider:

var main = [] 

now want generate many (289 exact) arrays elements in main one. each of these arrays have like:

var subobject = {x:"a", y:"b", terrain:"c", note:"d"} 

generating values no problem, , can put values in defined subobject = {} , push(), can't figure out how iterate script each time creates new object , push() var main.

the naming of subobject unimportant, i'm looking solution inwhich can pull specific information such as:

main[0].x // x value of subarray in 0 location in main main[5].note// note value of subarray in 5 location in main 

(would make difference if every array had same name? since never access subobject directly (after being pushed main), through main[x].yyy or have via main[x].subarray[y] ?)

for (var = 0; < 289; i++) {       main.push({x: getrandomx(), y: getrandomy(), terrain: getterrain(), note: ""}); } 

as long create new objects {} before push them array ok. doesn't matter if assign new object same variable (ie subobject)

you access them later this:

main[0].x // value of x of first element 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -