Array的使用技巧

简介: Array的使用技巧   There are many instances when you might want to loop through all the elements of an array.

Array的使用技巧

 

There are many instances when you might want to loop through all the elements of an array. For example, by looping through an array containing references to sprites, you can perform a particular action on each of the sprites:

for (var i:int = 0; i < sprites.length; i++){  // Move each sprite one pixel to the right.  sprites[i].x++;}

 

You can store the array's length in a variable rather than computing it during each loop iteration. For example:

var length:int = sprites.length;for (var i:int = 0; i < length; i++){  // Move each sprite one pixel to the right.  sprites[i].x++;}

 

The effect is that there is a very marginal performance improvement because Flash doesn't have to calculate the length during each iteration. However, it assumes that you are not adding or removing elements during the loop. Adding or removing elements changes the length property. In such a case, it is better to calculate the length of the array with each iteration.

 

 public native function splice(startIndex:int, deleteCount:uint, ... values):Array;

相关文章
|
21天前
Array.from() 与 Array.reduce()
Array.from() 与 Array.reduce()
13 1
|
1天前
|
存储 机器学习/深度学习 JavaScript
array
array
7 2
|
4月前
|
JavaScript
Array concat()
Array concat()
|
8月前
|
索引
Array 数组
Array 数组
56 0
|
索引
Array.forEach()
Array.forEach()
61 0
|
存储
Array
Array
118 0
|
人工智能 索引
Even Array
Even Array
100 0
Even Array
|
存储 索引
你真的用对 Array.map() 了吗
你真的用对 Array.map() 了吗
125 0
|
Java C# 索引
C# 数组(Array)
基础知识 声明数组 datatype[] arrayName; 初始化数组: 声明一个数组不会在内存中初始化数组。当初始化数组变量时,您可以赋值给数组。 数组是一个引用类型,所以您需要使用 new 关键字来创建数组的实例。 例如: double[] balance = new double[10]; 您可以在声明数组的同时给数组赋值,比如: double[] balance = { 2340.0, 4523.69, 3421.0}; 您也可以创建并初始化一个数组,比如: int[] marks = new int[5] { 99, 98, 92, 97, 95}; 在上述情况下,你
197 0
|
算法
Array.prototype.sort 你真的掌握了吗?
Array.prototype.sort 你真的掌握了吗?
86 0

热门文章

最新文章