zoukankan      html  css  js  c++  java
  • [AS3]as3中splice和slice的用法介绍说明

    splice

    删除数组一段连续的元素,返回被删除的元素数组

    var arr:Array = ["a","b","c","d","e","f","g"];  
    arr.splice(删除点的索引,要删除的个数,新元素1,新元素2);  
    arr.splice(2,3,"o","p","q");//从索引为2开始,删除3个元素,并插入3个新元素"o","p","q" 
    arr.splice(-2,3,"o","p","q");//从倒数为2的索引开始,删除3个元素,并插入3个新元素"o","p","q" 
    arr.splice(2,3);//cuplayer.com提示:单纯的删除从索引2开始的3个元素(不插入)  
    arr.splice(2);//cuplayer.com提示:单纯的删除从索引2开始的所有元素(不插入)  
    arr.splice(2,0,"x","y","z");//在索引2的后面插入3个新元素(不删除) 
    

    slice

    获取数组中的部分元素

    var arr:Array = ["a","b","c","d","e","f","g"];  
    var newArr:Array = arr.slice();//浅复制数组  
    var newArr:Array = arr.slice(2);  
    var newArr:Array = arr.slice(-2);  
    var newArr:Array = arr.slice(2,5);  
    

      

    文章出处:http://www.cuplayer.com/player/PlayerCodeAs/2012/1106544.html

  • 相关阅读:
    linux 常用命令
    博客园兼容手机端
    博客园点击页面,显示句子
    win10 系统禁止自动更新
    php获取数组中第一个元素或最后一个元素
    设计模式
    高并发抢购
    mySql 数据库优化
    3dMax+VR的安装步骤
    3dmax
  • 原文地址:https://www.cnblogs.com/dt1991/p/4648407.html
Copyright © 2011-2022 走看看