Queue Method & Reorder method for array--js study note 2015-6-27 (68th Day)

Source: Internet
Author: User

Queue method

A LIFO "LIFO " access rule relative to the stack data structure, and the access rules for the queue data structure are FIFO

Here refers to a method shift (); It is able to move the first item in the array and return the item, while reducing the length of the 1;//by a bit like pop ()

Instance:

var colors = [' red ', ' green '];

var item = Colors.shift ();

alert (colors); Green

alert (item); Red

Alert (colors.length)//1;

A Unshift () method is also provided.

Usage and shift () opposite;

The shift () and unshift () operations are all the first items of the array;// push () and pop () are all for the tail of the array;

Unshift the length of the returned array;

Reorder Methods

The reverse () method is to reverse the original order of the array;

The sort () method is to arrange the array items in ascending order, which is the ToString () method that invokes the array, and then compares the resulting string to determine how to sort, note that even if each item value in the array is a number, the sort () method compares the string;

The sort () method can receive a comparison function as a parameter to specify which value is in front of which value;

Queue Method & Reorder method for array--js study note 2015-6-27 (68th Day)

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.