1:split 函數將字串以某個字元分割,將分割後的結果存入字串陣列中
function SplitUsersInformation(users) {
var usersArray = users.split(';');
> 🎜>
2:substr 函數切割目標字串
程式碼如下:
currentStr = currentStr .substr(0, currentStr.length - 2);
3:push 方法向Array中添加一條記錄
var totalUsers = new Array();
function PushItem(name, departmemt) {
function PushItem(name, departmemt) { ();
currentUser.UserName = name;
currentUser.Department = departmemt;
totalUsers.push(currentUser}的堆疊中彈出最上面的那筆記錄
複製程式碼
程式碼如下: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..F() ;
//totalUsers中會剩下user1,因為user2在堆疊的最上方,被彈出
5:splice 方法從Array中刪除指定的某條或多筆記錄
複製程式碼
程式碼如下:var totalUsers = new Array(); var totalUsers = new Array();
to (...);
function SpliceItem(name) { for (var i = 0; i .splice (i, 1)
}
}
}