Home > Web Front-end > JS Tutorial > Introduction to related methods of JS (JQuery) operating Array_javascript skills

Introduction to related methods of JS (JQuery) operating Array_javascript skills

WBOY
Release: 2016-05-16 17:00:45
Original
1068 people have browsed it

1: The split function splits the string according to a certain character and stores the split result in the string array

Copy code The code is as follows:

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

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

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

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

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

4: pop method from Array Pop the top record from the stack
Copy the code 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() ;
//There will be user1 left in totalUsers, because user2 is at the top of the stack and will be popped

5: The splice method deletes one or more specified records from the Array
Copy code 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 labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template