Use of Javascript methods

Source: Internet
Author: User

(1): Add an element to the array: var array = [];

    VaR
Array = [];
  Array. Push (123 );
  Array. Push (456 );
  Array. Push (false );
  Array. Push ("M ");
  Array. Push ("");
  Array. Push ("S ");
  
  For (VAR item in array ){
   Alert (typeof
Array [item]);
  }

(2) Pop pops up the elements in the array.

VaR array = [];
  Array. Push (123 );
  Array. Push (456 );
  Array. Push (false );
  Array. Push ("M ");
  Array. Push ("");
  Array. Push ("S ");
  VaR Len = array. length;
 
  For (VAR
I = 0; I <Len; I ++ ){
   Alert (array. Pop ());

  }
  Alert ("length of the last array:" + array. Length );

(3) join

VaR array = [];
  Array. Push (123 );
  Array. Push (456 );
  Array. Push (false );
  Array. Push ("M ");
  Array. Push ("");
  Array. Push ("S ");
  VaR str1 = array. Join (",");
  VaR str2 = array. Join ("| ");
  Alert (str1 );
  Alert (str2 );

The printed result is:

123,456, false, M, A, S
Concatenates an array into a string.
123 | 456 | false | M | A | S
Use | to cut the array into a string...

(4) Contact 
Combine the arrays another and another2 into an array (all the elements of the three arrays are available)

 VaR Bigarray=Array. Concat (another,Another2 ); 

(5)

Alert (bigarray. Slice (5, 9 ));Returns the starting position of the first parameter to the ending position of the second parameter. The array itself is not affected.

(6) splice Method

 

1.
Bigarray. splice (5,2 );     

2:Bigarray. splice (5,0,"","B ","B ","D "); 

 


The first line of code indicates that two elements are deleted from the bigarray array and the second line of code indicates that 0 elements are deleted from the first element, insert all subsequent parameters to the starting position from 5th.     

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.