JS of JQuery operation method of Array

  • 2020-03-30 01:41:11
  • OfStack

1: the split function splits the string by a character and stores the split result in a string array

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

2: the substr function cuts the target string

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

3: push method adds a record to the Array

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

The pop method pops the top record from the stack of Array

var totalUsers = new Array();
var user1 = new Object();
user1.UserName = "haha";
user1.Department = "hahahaha";
var user2 = new Object();
user2.UserName = "lolo";
user2.Department = "lolololo";
//I'm going to be left with user1 in totalUsers, because user2 is at the top of the stack, and it pops up

5: the splice method deletes a specified record or records from the Array

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

Related articles: