I’m trying to dynamically build a javascript array where _tags is a globally defined array and then send it to php via ajax request. Basically I need the uid as a key and x,y as a sub array. in php it would look something like
$arr[$uid] = array('x'=>$x,'y'=>$y);
but im having trouble figuring out an array like this in javascript, heres what i have
function add_tag_queue(uid,x,y){
var arr = new Array(3);
arr[0] = uid;
arr[1] = x;
arr[2] = y;
_tags.push(arr);
}
Im not sure what youre saying exactly here. The second example i previously gave assumes there is a single x,y pair for each
uidbut places no limits on how manyuids are in_tags. Thats whyvar _tags = {};is ourside of the function – so its a global variable.The following modifications would allow you to have multiple x,y pairs for each
uid:This should work:
if you want the
uidas the key then you need to use an object/hash not anarray