1. Create an Array object (in the case of an initial value) two methods:
var acolor=new Array (' Red ', ' black ', ' yellow ');
Alert (acolor.tostring ());//output:red,black,yellow
var acolor=[' red ', ' black ', ' blue ';
Alert (acolor.tostring ());//output:red,black,blue
2.length: Get array length
3.toString (): Outputs all the elements in an array.
Alert (acolor.tostring ());////output:red,black,yellow
4.valueOf (): Same 3
5.join (): Concatenate array value, connect array through connector, return linked string
Eg.alert (Acolor.join ("->"));//output:red->black->yellow
(string) 6.split (): Splits a string into an array of characters, where split ("") splits the string into a single character array, eg. Str "split into S,t,r
7.contact (): Attaches the parameter to the end of the array, the returned function value is the new Array object
eg.
var acolor=new Array (' Red ', ' black ', ' yellow ');
var acolorcon=acolor.concat ("1", "2");
Alert (acolorcon.tostring ());//output:red,black,yellow,1,2
8.slice (): Returns a new array with the specified item.
9.push ()/pop ():p Ush () adds an item at the end of the array, POPs () deletes the last array item and returns the item value.
eg.
var acolor=new Array (' Red ', ' black ', ' yellow ');
Acolor.push ("Blue");
Acolor.push ("white");
Alert (acolor.tostring ());
Acolor.pop ();
Alert (acolor.tostring ());
10.shift (): Deletes the first item in the array
11.unshift (): Adds the first item to the array, and the other items are moved back.
var acolor=new Array (' Red ', ' black ', ' yellow ');
Acolor.shift ();
Alert (acolor.tostring ());
Acolor.unshift ("Red");
Alert (acolor.tostring ());
12.reverse (): Reverses the order of the array items.
13.sort (): Sorted in ascending order of an array of items.
eg.
var acolor=new Array (' Red ', ' black ', ' yellow ');
Acolor.sort ();
alert (Acolor);
Alert (Acolor.reverse ());
14.splice ().
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.