Angularjs applications, common array knowledge points

Source: Internet
Author: User




3:{} added code ": True|false", separated by commas, you can control including the style, display and hide functions,}

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

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 elements of the insertion position are automatically moved back, and the "" is returned.

4. Deletion of array elements

Arrayobj.pop (); // removes the last element and returns the element value

Arrayobj.shift (); // Remove the first element and return the element value, the elements in the array are automatically moved forward

Arrayobj.splice (Deletepos,deletecount); // deletes the specified number of DeleteCount elements from the specified position deletepos, returning the removed element 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]]]); // to concatenate multiple arrays (which can also be strings, or a mixture of arrays and strings) into an array, returning a new concatenated array

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

3 properties of an array object

1, Length property,Length property represents the size of the array, that is, the number of elements therein. The index always starts at 0, so the upper and lower bounds of an array are: 0 and length-1, respectively.

2. Prototype Properties

Returns a reference to the object type prototype. The prototype property is common to object.


The ObjectName parameter is the name of the object.

3. Constructor properties

Represents a function that creates an object.

Object.constructor//object is the name of the object or function.

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: 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.