JS Tutorial Series 24:javascript-array

Source: Internet
Author: User
Tags array sort

1 Arrays-reference types

Built-in objects in JavaScript review arrays using two ways to create arrays array object's property length gets the lengths of the array (number of elements)

2 Common methods:Detecting Arrays

New in instanceof Array.isarray ()//html5

Converting Arrays

ToString ()//Convert the array to a string, each with, split

ValueOf ()//Returns the array object itself join

-Stack operation (advanced post-exit)

-push ()

Pop ()//Remove the last item in the array, modify the Length property

-Queue Operations (FIFO)

-push ()

-shift ()//Remove the first element in the array, modify the Length property

-unshift ()//insert item at the top of the array, return the length of the array

-Sorting Method

Reverse ()//Flip Array

Sort (); Even the array sort is also based on characters, from small to large

How is the sort with parameters implemented?

// join is to link the elements of an array into a string in a special way (the parameter determines what link to use, and the default is a comma link)    var arr = ["AA", "BB", "BB"];     var str1 = arr.join ();     var str2 = Arr.join (""); // If you use a space, there will be a space    between the elements. var str3 = Arr.join (""); // Use empty strings, link elements, seamlessly connect    var str4 = Arr.join ("&");    Console.log (STR1);    Console.log (STR2);    Console.log (STR3);    Console.log (STR4);
3 Other common methods
vararr = ["Guan Yu", "Zhang Fei", "Liu Bei"]; varARR2 = [A]; Console.log (arr);////add element at the end of the array (returns the length of the new array)   //var aaa = Arr.push ("abc");   varAAA = Arr.push ("abc", "Def"); //var aaa = Arr.push (ARR2);   //Console.log (AAA);   //Console.log (arr);//////Deletes an element at the very end of the array (returns the newly deleted element)   //AAA = Arr.pop ();   //Console.log (AAA);   //Console.log (arr);    //Unshift adding elements to the front of the arrayAAA = Arr.unshift ("abc"));    Console.log (AAA);    Console.log (arr); AAA=Arr.shift ();    Console.log (AAA); Console.log (arr);

 varARR1 = ["A", "B", "C"]; varARR2 = [A]; //concat to link the array together    varARR3 =Arr1.concat (ARR2);//Console.log (arr1);//Console.log (ARR2);Console.log (ARR3); //interception of Slice arrays//var arr4 = Arr3.slice (2);//["C", [+]    //var arr4 = Arr3.slice ( -2);//[2,3]   //var arr4 = Arr3.slice (4,2);//[]   //var arr4 = Arr3.slice (2,4);//["C", 1] The index value includes the coordinates that do not include the right side. //Console.log (ARR3);//Console.log (ARR4);////splice manipulating and intercepting the original array//var arr5 = ["1111", "1111", "1111"];//the//replacement element cannot exist as an array, otherwise the entire array is put into the original array.     varARR4 = Arr3.splice (0,3, "1111", "1111", "1111"); Console.log (ARR3);//Console.log (ARR4);

JS Tutorial Series 24:javascript-array

Related Article

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.