ActionScript 3 AS3在阵列上使用Push,Pop,Unshift和Shift

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ActionScript 3 AS3在阵列上使用Push,Pop,Unshift和Shift相关的知识,希望对你有一定的参考价值。

var myArray:Array = new Array();


// PUSH
// Adds one or more elements to the end of an array and returns the new length of the array.
myArray = ["a","b","c","d"];
trace(myArray);
myArray.push("e");
trace(myArray);
// OUTPUT
// a,b,c,d
// a,b,c,d,e


// POP
// Removes the last element from an array and returns the value of that element.
myArray = ["a","b","c","d"];
trace(myArray);
myArray.pop();
trace(myArray);
// OUTPUT
// a,b,c,d
// a,b,c


// UNSHIFT
// Adds one or more elements to the beginning of an array and returns the new
// length of the array. The other elements in the array are moved from their 
// original position, i, to i+1.
myArray = ["a","b","c","d"];
trace(myArray);
myArray.unshift("_");
trace(myArray);
// OUTPUT
// a,b,c,d
// _,a,b,c,d



// SHIFT
// Removes the first element from an array and returns that element.
// The remaining array elements are moved from their original position, i, to i-1.
myArray = ["a","b","c","d"];
trace(myArray);
myArray.shift();
trace(myArray);
// OUTPUT
// a,b,c,d
// b,c,d

以上是关于ActionScript 3 AS3在阵列上使用Push,Pop,Unshift和Shift的主要内容,如果未能解决你的问题,请参考以下文章

ActionScript 3 AS3阵列差异

ActionScript 3 AS3:优化阵列(AKA矢量)

ActionScript 3 AS3:删除阵列中的重复项

ActionScript 3 AS3检查两个不同阵列中的所有值是否相同

ActionScript 3 AS3:在图像上放置叠加层

ActionScript 3 AS3:在舞台实用程序上对齐对象