Push (), pop (), Shift (), unshift (), splice (), join (), concat (), sort (), split (), parseint ()// Array----------------------------------------------------------------------------------------
var arr=[1,2,3];
var arr=new Array (n/a); Array definition
Arr.push (4); Rear Push-in 4
Alert (arr);
arr=[1,2,3];
Arr.unshift (4); Head pressed into 4
arr=[1,2,3];
Arr.pop (); Pop up the last one
Arr.shift (); pops up the first one
Alert (arr);
arr=[1,2,3,4,5,6,7,8];
Arr.splice (2,3); Intermediate Delete, Result: 1,2,6,7,8
arr=[1,2,3,4,5,6,7,8];
Arr.splice (5,0, ' A ', ' B ', ' C '); Intermediate INSERT, Result: 1,2,3,4,5,a,b,c,7,8
arr=[1,2,3,4,5,6,7,8];
Arr.splice (, ' A ', ' B '); Replacement, Result: 1,a,b,4,5,6,7,8
arr=[1,2,3,4];
arr.length=10;
Alert (arr[6]); Results: undefined
arr=[1,2,3,4];
Arr.join (': '); Results: 1:2:3:4
Character sorting
Vvar arr=[' float ', ' zindex ', ' xy ', ' absolute ', ' Blue ', ' Leo '];
Arr.sort (); Results: [' absolute ', ' blue ', ' float ', ' Leo ', ' xy ', ' zindex ']
Sort by number
var arr=[96, 8, 12, 72, 33, 118];
Arr.sort (function (num1,num2) {return num1-num2;}); Result: 8,12,33,72,96,118//array traversal var obj={a:5, B:3, c:98};
var attr= ';
for (attr in obj) {alert (attr+ ' = ' +obj[attr]);} Results pop up in turn: a=5,b=3,c=98
String--------------------------------------------------------------------------------------
var arr1=[1,2,3];
var arr2=[6,7,8];
Arr1.concat (ARR2); Array connection, Result: 1,2,3,6,7,8
var arr1= "SDSAFKASD";
var arr2= "55131535";
Arr1.concat (ARR2); string connection, Result: sdsafkasd55131535
var str= ' 12-4-5-8 ';
var arr=str.split ('-'); String split array, result: [12,4,5,8]
var str= ' 12 ';
parseint (str) +1; The string is converted to a number, the result: 13, otherwise 121
Good taste: Array and string common operations