javascript - Access an array item in its definition, relative index -
i trying define array:
postlists = [ [ [46276,76235,78128], postlists[0][0].length, 1100 ], [ [], postlists[1][0].length, 0 ] ];
however, undefined error postlists[x][0].length
lines.
how access array being defined itself? there way relatively select item without referencing entire "path" folders? example in case, [0].length
[46276,76235,78128]
's length, or ..[1]
(parent) select postlists[1]
.
postlists[x][0]
hold hundreds of thousands of integers, performance need considered.
postlists[x][1]
original length needs accessed every few seconds, because of size of postlists[x][0]
, cannot accessed on fly without harming performance.
postlists[x][2]
index keep track (and store) items processed, in postlists[0][2]
1100
used skip 1100 first items have been processed.
i using in greasemonkey script, reason sub-arrays in postlists plan use script on multiple tabs running @ same time.
the start of script setup this:
window.onkeydown = function(event) { if (event.ctrlkey && event.altkey) { switch(event.keycode) { case 49: activelist = postlists[0]; break; // 1 case 50: activelist = postlists[1]; break; // 2 case 51: activelist = postlists[2]; break; // 3 case 52: activelist = postlists[3]; break; // 4 case 70: // f togglescript = !togglescript; if (togglescript) { treatitem(); favobserver.observe(topnotice, {attributes: false, childlist: true, characterdata: true}); } else stopobserving(true); break; } } };
every functions use activelist
refer selected sub-array.
you can utilize assignment, side-effect of creating additional variable; e.g., tmp
, used assign, re-assign variable can change multiple occassions
var tmp, postlists = [ [ tmp = [46276, 76235, 78128], tmp.length, 1100 ], [ tmp = [], tmp.length, 0 ] ]; delete tmp; console.log(postlists);
Comments
Post a Comment