JavaScript array functions

Source: Internet
Author: User
Tags javascript array

Declaring an array

var tmp=[];//简写模式var tmp= new Array();//直接new一个var tmp=array();  //直接new一个

In the new array, you can pass in a parameter that represents the initialization length of the array.

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

Unshift inserting an element before the first element of the array

//使用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 pops the value of the first element of the array, returning the value of the element being popped

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

Push adds an element at the end of the array, returning the length of the array after the element is added

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

The pop function deletes the element at the end of the array

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

JavaScript array functions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.