Methods of Arrays (i)

Source: Internet
Author: User

1, usually we will use the way to insert data into the array is push, it is also used, but it should be noted that the push method has a return value.

var arr = [1,2,3];alert (Arr.push ('aaaaaa' ) )    //The Push method returns the array length of alert (arr);        Alert (Arr.unshift ('bbbbb'));   // push is inserted backwards, and unshift is inserted forward, it is understood to hold down the head forward insertion, homophonic (convenient memory). The return value is also the array length alert (arr); // It is worth noting that IE6, IE7 is not support unshift return value, but return underfined. 

2.

var arr = ['aa','bb','cc'  ];alert (Arr.pop ());     // Delete the last array, the return value is deleted. Pop homophonic Cindy Managed, put a fart back. (easy memory)alert (arr); alert (Arr.shift ());   // Delete the first of the array, the return value is deleted. alert (arr);

3, the use of four methods, you can do the array content "transposition Walk"

varARR1 = ['AA','BB','cc','DD'];arr1.unshift (Arr1.pop ()); //results: DD,AA,BB,CCalert (arr1);varARR2 = ['AA','BB','cc','DD'];arr2.push (Arr2.shift ()); //results: Bb,cc,dd,aaalert (ARR2);

Methods of Arrays (i)

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.