JS How to add an element to an array of arrays

Source: Internet
Author: User

Reprinted from: http://blog.sina.com.cn/s/blog_95fa28e60101mwup.html

Unshift: Adds a parameter to the beginning of the original array and returns the length of the array
Pop: Deletes the last item of the original array and returns the value of the deleted element; returns undefined if the array is empty
Push: Adds a parameter to the end of the original array and returns the length of the array
Concat: Returns a new array that consists of adding parameters to the original array
Splice (Start,deletecount,val1,val2,...) : Deletes the DeleteCount entry starting from the start position and inserts the Val1,val2 from that position,...
Reverse: Reverse the array
Sort (orderfunction): Sorts the array by the specified parameters
Slice (Start,end): Returns a new array that consists of the entries from the original array that specify the starting subscript to the end subscript


With:
1. Creation of arrays
var arrayobj = new Array (); Create an array
var arrayobj = new Array ([size]); Create an array and specify the length, note not the upper limit, is the length
var arrayobj = new Array ([element0[, element1[, ... [, ELEMENTN]]]); Create an array and assign a value

To illustrate, although the second method creates an array that specifies the length, the array is actually variable in all cases, meaning that even if the length is 5, the element can still be stored outside the specified length, note that the length changes accordingly.
2. Access to elements of an array
var testgetarrvalue=arrayobj[1]; Gets the element value of the array
Arrayobj[1]= "This is the new value"; Assigning a new value to an array element
3. Adding array elements
Arrayobj. Push ([Item1 [item2] [... [Itemn]]); /Adds one or more new elements to the end of the array and returns the new length of the array
Arrayobj.unshift ([Item1 [item2 [...] [Itemn]]); /Adds one or more new elements to the beginning of the array, the elements in the array are automatically moved back, returning the new length of the array
Arrayobj.splice (insertpos,0,[item1[, item2[, ... [, Itemn]]]); /inserts one or more new elements into the specified position of the array, the element at the insertion position automatically moves back, and returns "".
4. Deletion of array elements
Arrayobj.pop (); Removes the last element and returns the element value
Arrayobj.shift (); Removes the first element and returns the element value, and the elements in the array are automatically moved forward
Arrayobj.splice (Deletepos,deletecount);//delete the element that is removed from the specified number of DeleteCount elements, starting at the specified position deletepos, as an array
5. Interception and merging of arrays
Arrayobj.slice (start, [end]); Returns a portion of the array as an array, noting that the element of end is not included, and if the end is omitted, all elements after start are copied
Arrayobj.concat ([item1[, item2[, ... [, Itemn]]]); /concatenate multiple arrays (which can also be strings, or a mixture of arrays and strings) into an array, returning a new concatenated array
Finishing: www.mls169.com
6, copy of the array
Arrayobj.slice (0); Returns a copy array of the array, note that it is a new array, not a pointer to the
Arrayobj.concat (); Returns a copy array of the array, note that it is a new array, not a pointer to the
7. Sorting of array elements
Arrayobj.reverse (); Reverses the element (the top row to the last and last to the top), returning the array address
Arrayobj.sort (); Sort the array elements, returning the address of the arrays
8. String of array elements
Arrayobj.join (separator); Returns a string that connects each element value of an array, separated by separator.
toLocaleString, toString, valueOf: Can be seen as a special use of joins, not commonly used

JS How to add an element to an array of arrays

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.