开发者

Count only the set indexes of Array?

in PHP you can do something like this:

Array1 =开发者_开发知识库 0,0,3,6,6,6,7,8,8,9

Then loop through Array1 and set the keys of Array2

Array2[0] = true;
Array2[3] = true;
Array2[6] = true;
Array2[7] = true;
Array2[8] = true;
Array2[9] = true;
Array2.count = 6;

But doing a similar thing in AS3 would result in a count of 10 (true,,,,true,,,,true,true,true,true) as all of the keys that are not set are counted. Is there a way of doing this without using any more loops? or functions, simplicity and efficiently are important here.


This occurs because by default, actionscript arrays are dense arrays. This means that these arrays do not leave empty spaces between indexes.

If you really need to optimize, you can use an associative array or dictionary

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜