[b]join()方法:[/b]
[b]reverse()方法:[/b]
[b]sort()方法:[/b]
[b]concat()方法:[/b]
[b]join()方法:[/b]
[b]slice()方法:[/b]
[b]splice()方法:[/b]
var a = [0,1,2];//用这三个数字创造一个新数组
var s1 = a.join();//s1 = "0,1,2"
var s2 = a.join(", ");//s2 = "0, 1, 2"
[b]reverse()方法:[/b]
var a = [0,1,2];//用这三个数字创造一个新数组
a.reverse();//a[0] = 2,a[1] = 1,a[2] = 0
var s = a.join();//s = "2,1,0"
[b]sort()方法:[/b]
var a = ["banana","cherry","apple"];//用这三个字符串创造一个新数组
a.sort();//对数组元素排序,返回排序后的数组
var s = a.join();//s = "apple,banana,cherry"
var a = [33,3,1111,222];
a.sort; //按字母排序 11111,222,33,4
a.sort(function(a,b){ //按数字排序 4,33,222,1111
return a-b;
});
[b]concat()方法:[/b]
var a = [0,1,2];//用这三个数字创造一个新数组
a.concat([3,4]); //[0,1,2,3,4]
a.concat(3,4); //[0,1,2,3,4]
a.concat([3,4],[5,6]);//[0,1,2,3,4,5,6]
a.concat(3,[4,[5,6]]);//[0,1,2,3,4,[5,6]]//不能递归展开元素为数组的数组
[b]join()方法:[/b]
var a = [0,1,2];//用这三个数字创造一个新数组
var s1 = a.join();//s1 = "0,1,2"
var s2 = a.join(", ");//s2 = "0, 1, 2"
[b]slice()方法:[/b]
var a = [0,1,2,3,4];//用这5个数字创造一个新数组
a.slice(0,3); //[0,1,2]
a.slice(3); //[3,4]
a.slice(1,-1);//[1,2,3]
[b]splice()方法:[/b]
var a = [0,1,2,3,4];//用这5个数字创造一个新数组
a.splice(4); //返回[4]a是[0,1,2,3]
a.splice(1,2); //返回[1,2]a是[0,3]
a.splice(1,1); //返回[3]a是[0]
var a = [0,1,2,3,4];//用这5个数字创造一个新数组
a.splice(2,0,'a','b');//返回[]a是[0,1,'a','b',2,3,4]
a.splice(2,2,[1,2],3);//返回时['a','b'],a是[0,1,[1,2],3,3,4]