JavaScript unshift () and Shift ()

Source: Internet
Author: User

<HTML><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8" /></Head><Body><Scripttype= "Text/javascript">Console.log ('the behavior of the Unshift () and Shift () methods is very similar to push () and pop (), unlike the insertion and deletion of elements in the head of an array rather than the tail. '); Console.log ('Unshift () adds one or more elements to the head of the array and moves the existing elements to a higher index to get enough space and finally returns the new length of the array. '); Console.log ('shift () deletes the first element of the array and returns it, and then moves all subsequent elements down one position to fill the empty array header. ');vara=[];varret=A.unshift (1); Console.log ('a.unshift (1) a='+a+': ret='+ret); RET=A.unshift ( A); Console.log ('A.unshift (a=)'+a+': ret='+ret); A.shift (); Console.log ('a.shift () a='+a+': ret='+ret); A.unshift (3,[4,5]); Console.log ('A.unshift (3,[4,5]) a='+a+': ret='+ret); A.shift (); Console.log ('a.shift () a='+a+': ret='+ret); A.shift (); Console.log ('a.shift () a='+a+': ret='+ret); A.shift (); Console.log ('a.shift () a='+a+': ret='+ret);</Script></Body></HTML>

JavaScript unshift () and Shift ()

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.