JS函数大全------数组函数(五)01-01
不是正宗的JS好手,对JS的系统函数掌握甚少,当进行JS数据处理时,总是感觉少了什么东西,这种感觉多了,就行可能是JS的内部函数没有足够的掌握熟悉,同时jQuery用的多了,JS的系统函数也是用的少,于是乎,现在找到了点,总结一下。
再然后是数组函数(Array):
1.声明
var arr = new Array(); //声明一个空数组
var arr = new Array(10); //声明一个10个长度的数组
var arr = new Array("Alice", "Fred", "Jean"); //用值初始化数组
var arr = ["Alice", "Fred", "Jean"]; //用值初始化数组
var arr = [["A","B","C"][1,2,3]]; //声明一个二(多)维数组
2.数组的访问
arr[0] = "123"; //赋值
var str = arr[0]; //获取
arr[0][0] = "123"; //多维数组赋值
3.数组与字符串间的转换
var arr = ["A","B","C","D"]; //声明
//数组按分隔符转换成字符串
var str = arr.join("|"); //结果: "A|B|C|D"
//字符串切割成数组
arr = str.split("|");
4.遍历数组
for( var i=0; i<arr.length; i++ ){ alert(arr[i]); }
5.排序
var arr = [12,15,8,9];
arr.sort(); //结果: 8 9 12 15
6.组合与分解数组
var arr1 = ["A","B","C","D"];
var arr2 = ["1","2","3","4"];
//奖两个数组组合成一个新的数组
var arr = arr1.concat(arr2); //结果: ["A","B","C","D","1","2","3","4"]
//将一个数组切成两个数组(参数1:起始索引,参数2:切割长度)
var arr3 = arr.splice(1,3); //结果: arr3: "B","C","D"] arr["A","1","2","3","4"]
//将一个数组切成两个数组,并在原数组补新值
var arr4 = arr.splice(1,3,"AA"); //结果: arr4:["B","C","D"] arr["A","AA","1","2","3","4"]
- encodeURI和encodeURIComponent的区别 2015-05-12
- zepto.js和jquery.js的优劣 2015-02-04
- 在JS中调用PHP变量 2015-01-07
- JS获取支持的字体列表 2015-01-01
- JS函数大全------浏览器函数(四) 2015-01-01