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)
}
}
}