SoFunction
Updated on 2025-04-11

Introduction to the related methods of JS (JQuery) operating Array

1: The split function divides the string by a certain character and saves the split result into the string array

Copy the codeThe code is as follows:

function SplitUsersInformation(users) {
    var usersArray = (';');
    return usersArray;
}

2: The substr function cuts the target string
Copy the codeThe code is as follows:

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

3: The push method adds a record to Array
Copy the codeThe code is as follows:

var totalUsers = new Array();
function PushItem(name, departmemt) {
    var currentUser = new Object();
    = name;
    = departmemt;
    (currentUser);
}

4: The pop method pops the top record from the Array stack
Copy the codeThe code is as follows:

var totalUsers = new Array();
var user1 = new Object();
= "haha";
= "hahahaha";
var user2 = new Object();
= "lolo";
= "lolololo";
(user1);
(user2);
();
//There will be user1 left in totalUsers, because user2 is at the top of the stack and is popped up

5: The splice method deletes a specified record or records from Array
Copy the codeThe code is as follows:

var totalUsers = new Array();
(...);

function SpliceItem(name) {
    for (var i = 0; i < ; i++) {
        if (totalUsers[i].UserName == name) {
            (i, 1)
        }
    }
}