Introduction to JS (JQuery)-related methods for operating arrays _ javascript tips-js tutorial

Source: Internet
Author: User
This article mainly introduces the methods related to Array Operations in JS (JQuery). If you need them, please refer to them and hope to help you. 1: the split function splits the string by a specific character and saves the split result to the string array.

The Code is as follows:


Function SplitUsersInformation (users ){
Var usersArray = users. split (';');
Return usersArray;
}


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

The Code is as follows:


CurrentStr = currentStr. substr (0, currentStr. length-2 );


3: The push method adds a record to the Array.

The 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.

The 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.

The 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.