JavaScript Knowledge points Summary

Source: Internet
Author: User

Push/pop (method of removing elements at the beginning of the array), Unshift/shift (method to add and remove the end of the array)

var arr3 = [' B ', ' C ', ' d '];

Console.log (Arr3.unshift (' a '));//Add an element at the beginning of the array//number of elements in the printed array

Console.log (ARR3);

Console.log (Arr3.push (' e '));//Add an element to the end of the array

Console.log (ARR3);

var str2 = Arr3.shift ();//Remove the beginning of an element and return the element

Console.log (STR2);

Console.log (ARR3);

var str1 = Arr3.pop (); Removes an element at the end and returns the element

Console.log (STR1);

Console.log (ARR3);

There are already two methods in the array that can be used to sort directly: reverse () and sort ().

Reverse ()//reverse Sort

var box = [1,2,3,4,5];

Console.log (Box.reverse ()); Reverse Sort method, returns the sorted array

Console.log (box); The original array is also sorted backwards.

Sort ()//sorting

Sort (function (A, b) {return-A-B;})//from small to large

Sort (function (A, b) {return b-a;}) From the large to the small sort note that this method to pass the parameter does not pass the participant error such as array [1,10,2], after the sort is still [1,10,2]

var box = [4,1,7,3,9,2];

Console.log (function (A, b) {return-A-B}) (Box.sort); Sort from small to large, return sorted array

Console.log (box); The source array is also sorted from small to large.

JavaScript Knowledge points Summary

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.