How to create objects in an array in javascript -
hi i've been coding game in javascript, first, , i'm trying create objects in array. i've written following code i'm not sure if works properly. can verify or correct this?
for (i=0;i<10;i++){ objs [i] = '"i" = {x=(i*100),y=(i*100)}' }
thanks
i assume trying put objects in array.
first declare array
var objs = [];
then like
for (var i=0;i<10;i++){ objs[i] = {x:i*100,y:i*100} }
you had lot of superflous code in there.
you need learn how figure out if code works. interpreter chokes on example written. can open web tools, paste code in, , run it, start figuring out errors.
here fiddle might you.
Comments
Post a Comment