Array object learning in js

Source: Internet
Author: User
1. length attribute, which varies with the number of arrays. You can also manually set the syntax expression: numVar = arrayObj. the length2.concat () method returns a new array consisting of two or more arrays.

1. The length attribute, which varies with the number of arrays. You can also set it manually.
Syntax expression: numVar = arrayObj. length

2. The concat () method returns a new array consisting of two or more arrays.
Syntax expression: arr1.concat (arr2), indicating connecting arr2 to the end of arr1

3. push () adds the new element to an array and returns the new Length Value of the array.
Syntax expression: arrayObj. push ([item1 [item2 [... [itemN]) can be multiple arrays

4. pop () removes the last element from the array and returns the element.
Syntax expression: arr. pop ()

5. shift () removes the first element from the array and returns the element.
Syntax expression: arr. shift ()

6. unshift () inserts the specified element into the starting position of the array and returns the array.
Syntax expression: arr. unshift ("element 1", "element 2 ")

7. Convert the array elements into strings toString () and join ()
Syntax expression: arr. toString () arr. join ("separator ")

8. reverse () returns an Array object whose element order is reversed.
Syntax expression: arr. reverse ()

Example:


Script var arr = new Array ("abc", 123); var arr1 = new Array ("php"); document. write (arr. length +"
"); // 2document. write (arr. concat (arr1) +"
"); // Abc, 123, phpdocument. write (arr. push (" php ") +"
"); // 3document. write (arr. pop () +"
"); // Php click document. write (arr. shift () +"
"); // Running result: abc now the arr array has only 123 elements left with document. write (arr. unshift (" book ") +"
"); // Result 2 returns the array document. write (arr +"
"); // Book, 123document. write (arr. toString () +"
"); // Book, 123document. write (arr. join ("-") +"
"); // Book-123document.write (arr. reverse () +"
"); // 123, book script
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.