JS (jquery) related methods for operating Arrays

Source: Internet
Author: User

1: The split function splits the string by a specific character and saves the split result to the string array.

 
Function splitusersinformation (users ){
VaRUsersarray = users. Split (';');
ReturnUsersarray;
}

2: The substr function is used to cut the target string.

 
Currentstr = currentstr. substr (0, Currentstr. Length-2);

3: The Push method adds a record to the array.

VaRTotalusers =NewArray ();
Function pushitem (name, invalid memt ){
VaRCurrentuser =NewObject ();
Currentuser. Username = Name;
Currentuser. Department = Alibaba memt;
Totalusers. Push (currentuser );
}

4: The pop method pops up the top record from the array stack.

 VaR Totalusers = New Array ();
VaR User1 = New Object ();
User1.username = " Haha " ;
User1.department = " Hahahaha " ;
VaR User2 = New Object ();
User2.username = " Lolo " ;
User2.department = " Lolololo " ;
Totalusers. Push (user1 );
Totalusers. Push (user2 );
Totalusers. Pop ();
// User1 is left in totalusers, because user2 is displayed at the top of the stack.

5: The splice method deletes a specified record or multiple records from the array.

 
VaRTotalusers =NewArray ();
Totalusers. Push (...);

Function spliceitem (name ){
For(VaRI =0; I <totalusers. length; I ++ ){
If(Totalusers [I]. Username = Name ){
Totalusers. splice (I,1)
}
}
}

6: For details about how to operate array in JS, refer to this blog.

Http://hi.baidu.com/%B3%E8%C8%E8%B2%BB%BE%AA0521/blog/item/0cada15b302b20401038c237.html

 

 

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.