Introduction to JS (JQuery) 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.
Copy codeThe Code is as follows:
Function SplitUsersInformation (users ){
Var usersArray = users. split (';');
Return usersArray;
}

2: The substr function is used to cut the target string.
Copy codeThe Code is as follows:
CurrentStr = currentStr. substr (0, currentStr. length-2 );

3: The push method adds a record to the Array.
Copy codeThe Code is as follows:
Var totalUsers = new Array ();
Function PushItem (name, invalid memt ){
Var currentUser = new Object ();
CurrentUser. UserName = name;
CurrentUser. Department = Alibaba memt;
TotalUsers. push (currentUser );
}

4: The pop method pops up the top record from the Array stack.
Copy codeThe Code is as follows:
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.
Copy codeThe Code is as follows:
Var totalUsers = new Array ();
TotalUsers. push (...);

Function SpliceItem (name ){
For (var I = 0; I <totalUsers. length; I ++ ){
If (totalUsers [I]. UserName = name ){
TotalUsers. splice (I, 1)
}
}
}

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.