Tutorial on Array Operations in Angular. js, angular. js Array

Source: Internet
Author: User

Tutorial on Array Operations in Angular. js, angular. js Array

Preface

The development of front-end technologies is so fast that the emergence of a variety of excellent technologies and frameworks is simply overwhelming, keeping up with the trend of the times, learning to master new knowledge is naturally not easy. Recently I am studying Angular. js. I will share some of my experience and skills with you. The following article will introduce you to Angular. for more information about Array Operations in js, let's take a look at the detailed introduction.

1: ng-click, ng-model, ng-bind, ng-class, ng-hide, ng-app

2: placeholder,

3: {}: add the code ": true | false", separated by commas (,) to control functions including style, display, and hide ,}

1. Create an array

Var arrayObj = new Array (); // create an Array var arrayObj = new Array ([size]); // create an Array and specify the length. Note that it is not the upper limit, is the length var arrayObj = new Array ([element0 [, element1 [,... [, elementN]); // creates an array and assigns a value.

2. Access to array elements

Var testGetArrValue = arrayObj [1]; // obtain the array element value arrayObj [1] = "this is a new value"; // assign a new value to the array element

3. Add array elements

ArrayObj. push ([item1 [item2 [... [itemN]); // Add one or more new elements to the end of the array, and return the new length of the array arrayObj. unshift ([item1 [item2 [... [itemN]); // adds one or more new elements to the array. The elements in the array are automatically removed and the new length of arrayObj is returned. splice (insertPos, 0, [item1 [, item2 [,... [, itemN]); // insert one or more new elements to the specified position of the array. The inserted element is automatically removed and "" is returned "".

4. Deletion of array elements

ArrayObj. pop (); // remove the last element and return the value of arrayObj. shift (); // remove the first element and return the element value. The elements in the array are automatically moved forward to arrayObj. splice (deletePos, deleteCount); // deletes the specified number of deleteCount elements starting from deletePos in the specified position. The removed elements are returned in an array.

5. truncate and merge Arrays

ArrayObj. slice (start, [end]); // return part of the array in the form of an array. Note that the elements corresponding to the end are not included. If the end is omitted, all the elements after the start are copied to arrayObj. concat ([item1 [, item2 [,... [, itemN]); // concatenates multiple arrays (or strings, or arrays and strings) into an array and returns a new connected array.

6. Copy an array

ArrayObj. slice (0); // returns the copy array of the array. Note that it is a new array instead of pointing to arrayObj. concat (); // returns the copy array of the array. Note that it is a new array, not pointing

7. Sorting of array elements

ArrayObj. reverse (); // returns the array address arrayObj. sort (); // sorts array elements and returns the array address.

8. stringized array elements

ArrayObj. join (separator); // returns a string that connects each element value of the array and is separated by separator.

ToLocaleString, toString, valueOf: can be considered as a special use of join, not commonly used

Three attributes of an array object

1. The length attribute indicates the Length of the array, that is, the number of elements in the array. The index always starts from 0, so the upper and lower limits of an array are: 0 and length-1.

2. prototype attributes

Returns a reference to an object type prototype. The prototype attribute is common to objects.

objectName.prototype

The objectName parameter is the name of the object.

3. constructor attributes

The function that creates an object.

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

Summary

The above is all the content of this article. I hope the content of this article will help you in your study or work. If you have any questions, please leave a message to us. Thank you for your support.

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.