javascript 數組函數

來源:互聯網
上載者:User

標籤:聲明   rip   pre   /tmp   刪除   []   str   sga   ssg   

聲明數組

var tmp=[];//簡寫入模式var tmp= new Array();//直接new一個var tmp=array();  //直接new一個

在new數組的時候可以傳入一個參數,表示數組的初始化長度

var tmp = new array();數組的元素可以是任意的var tmp=[3,true,8.5,'ssgao',[a,b],{'name':'lin'}];

unshift 在數組的第一個元素前插入元素

//使用unshift在數組第一個元素前插入元素,並返回數組長度var tmp =['a','b'];var len= tmp.unshift('c');// len=3, tmp=[c,a,b]var len= tmp.unshift('d,e');//tmp=[d,e,a,b]

shift彈出數組的第一個元素的值,返回被彈出的元素值

var tmp=[a,b,c];var val=tmp.shift();//val=a,tmp=[b,c];

push在數組的末尾添加元素,返回添加元素以後數組的長度

var tmp=['a','b','c'];var len=tmp.push('d')//len=4 tmp=['a','b','c','d'];

pop 函數刪除數組末尾的元素

var tmp=['a','b','c'];var val=tmp.pop(); //val=c;tmp=['a','b']

javascript 數組函數

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.