08.18 JavaScript 06 array array concept create array read elements in array sparse array add and remove array elements array iterate over array of multidimensional array methods class array object as an array of strings

Source: Internet
Author: User
Tags array length

# array
The Concept of # # # array
* Array is an ordered set of values
* Each value in the array is called an element
* Each element can be a value of any data type
* Each element has an index (subscript)
* The index of the element starts at 0 and increments in order. The element's largest index 2^32-2

# # # Create an array
* Direct Volume ' [] '
* Constructor Method ' new Array () '


# # # Read and write elements in an array
* array name [index]


# # # Sparse Array
* The index of the JS array is continuous
* There is no continuous assignment to the element, and the element with no assignment is automatically assigned to the value undefined

< Span style= "COLOR: #008000" >
# # # Add and remove elements of an array
*  add an array element
    *   Specify an index to add an element
    *   The array length as the index of the new element    "Arr[arr.length ] = value '
    *   at the end of the array add element push ()    " Arr.push () '
    *   add element before array unshift ()    ' Arr.unshift () '
    *   add elements anywhere in a number array    Splice (index, 0, value)   

 

< Span style= "COLOR: #008000" > < Span style= "COLOR: #808080" >
*  delete elements of an array
    *    change the Length property of the array    ' arr.length-= 1;  arr.length-= 2 '
    *   Delete The most subsequent element   pop ()
    *   Deletes the first element of an array   shift ()
    *   deletes the specified number of elements at the specified position    splice ( index, length)



# # # Array traversal
* For Loop
* For in

 


Span style= "COLOR: #b22222" >### multidimensional array

### Array method
* join ([spacer symbol])     stitch Each element of an array into a string     return string
Span style= "COLOR: #808080" >* slice (start, end)     intercept part of the array, returning a new array
* concat (arr, arr ....)     merging arrays. Returns a new array
* tostring ()     converts an array to a string
* reverse ()    flip array side effects
* sort ()      sort    Side effects
* push () Pop ()    side effects
* shift ()   unshift ()    side effects

 

< Span style= "COLOR: #808080" > < Span style= "COLOR: #808080" >

### class Array Object
*  arguments
* elementcollection     elements  
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;
          document.getElementsByTagName ()
          element.getelementsbytagname ()

 

< Span style= "COLOR: #b22222" > < Span style= "COLOR: #808080" > < Span style= "COLOR: #008000" >

### the string as an array
Span style= "COLOR: #808080" The >*  string has a partial array attribute
*  string also has the length property to get the lengths of the string
. Span style= "COLOR: #808080" >*  can also remove a character from a string by [index value]

08.18 JavaScript 06 array array concept create array read elements in array sparse array add and delete array of elements array traversal method class array array object as array string

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.