开发者

actionscript array remove element

开发者 https://www.devze.com 2022-12-24 04:22 出处:网络
I have an array Items which has 10 elements. I need to remove the 5th element (index=4) the new array should ha开发者_运维知识库ve 9 elements and all elements after the 5th element will be shifted for

I have an array Items which has 10 elements. I need to remove the 5th element (index=4) the new array should ha开发者_运维知识库ve 9 elements and all elements after the 5th element will be shifted forward

what command(s) should i use?


Splice

http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/Array.html#splice%28%29

var vegetables:Array = new Array("spinach",
             "green pepper",
             "cilantro",
             "onion",
             "avocado");

var spliced:Array = vegetables.splice(2, 2);
trace(vegetables); // spinach,green pepper,avocado
trace(spliced);    // cilantro,onion

vegetables.splice(1, 0, spliced);
trace(vegetables); // spinach,cilantro,onion,green pepper,avocado
0

精彩评论

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