[AS3]as3关于数组方面的添加,删除,查找,字符串等介绍(2)
查找数组中第一个相匹配的元素 var array:Array =[a,b,c,d,a,b,c,d]; var match:String = b ; for(var i:int = 0 ;i array.length ;i++){ if(array[i]==match){ trace(Elementwithindex+i+foundtomatch+match); //
查找数组中第一个相匹配的元素
- var array:Array = ["a", "b", "c", "d", "a", "b", "c", "d"];
- var match:String = "b";
- for(var i:int = 0; i < array.length; i++) {
- if(array[i] == match) {
- trace("Element with index " + i + " found to match " + match);
- //输出: Element with index 1 found to match b
- break;
- }
- }
查找数组中最后一个相匹配的元素
- var array:Array = ["a", "b", "c", "d", "a", "b", "c", "d"];
- var match:String = "b";
- for(var i:int = array.length - 1; i >= 0; i--) {
- if(array[i] == match) {
- trace("Element with index " + i + " found to match " + match);
- //输出: Element with index 5 found to match b
- break;
- }
- }
把字符串转成数组
使用String.split()方法:
- var list:String = "I am YoungBoy.";
- var words:Array = list.split(" "); //以空格作为分隔符将字符串切割
- trace(words); //输出: I,am,YoungBoy.
把数组转成字符串
使用String.join()方法:
- var myArr:Array = new Array("one", "two", "three");
- var myStr:String = myArr.join(" and ");
- trace(myArr); //输出: one,two,three
- trace(myStr); //输出: one and two and three
热门文章推荐
- [HLS]做自己的m3u8点播系统使用HTTP Live Streaming(HLS技术)
- [FMS]FMS流媒体服务器配置与使用相关的介绍
- [AS3]什么是M3U8,与HTML5的区别是什么
- AS2.0 让flash自适应全屏,并且不自动缩放
- [AS3]as3.0的sound类常用技巧整理
- [AS3]as3与ByteArray详解、ByteArray介绍、ByteArray用法
- 关于RTMP,RTMPT,RTMPS,RTMPE,RTMPTE协议的介绍
- [JS]分享浏览器弹出窗口不被拦截JS示例
请稍候...