javascript 方法总结

Array
1.array.concat(item...)
instance:
    var a = ['2','3'];
    var b = ['4','5'];
    var c = a.concat(b,true);//c = ['2','3','4','5','true'];

2.array.join(separator)
instance:
    var a = ['1','2'];
    a.push('3');
    var c = a.join(',');//c:'1,2,3'
3.array.pop():remove last element in the array,it can be inplemented like that:
    Array.method('pop',function(){
        return this.splice(this.length - 1,1)[0];   
    })
4.array.push(item...):this method can push the element in the array,it can be implemented like that :
    Array.method('push',function(){
        this.splice.apply(
            this,
            [this.length,0]    .concat(Array.prototype.slice.apply(arguments)));
            return this.length;   
    });
5.array.reverse():反向排序
6.array.shift():remove the first element in the array,if the array is null then the method will return undefined
    Array.method('shift',function(){
        return this.splice(0,1)[0];
    })
7.array.slice(start,end):被复制的元素的end-1位。
8.array.sort:正向排序
9.array.splice(start,deletecount,item):移除一个或者多个的元素,用item里面的元素来替换
10.array.unshift(item...):add the element in the first of the array.

11.FUNCTION:
    function.apply(thisArg,argArray):apply调用function函数,传递一个将被绑定到this上的对象和一个可选的参数数组。
instance:
12.NUMBER:
    number.toExponential(fractionDigits):将number转换成指数型的字符串,可选参数fractionDigits控制其小数点后的数字位数,他的值必须在0~20之间
    .toFixed(fractionDigits):转成十进制的字符串
    .toPrecision(fractionDigits):可以控制输出的十进制的字符串的精度,fractionDigits代表精度值
    .toString(fractionDigits):fractionDigits是基数。
13.RegExp
    .exec(string):string是正则表达式的匹配因子。
14.String
    .charAt(pos):返回pos所指定的位置的元素
    .charCodeAt(pos):返回pos所指定的位置的元素的ASIIC
    .concat(String..):连接两个字符串
    .indexof(searchString,postition):从头开始找
    .lastindexof(searchString,pos):从尾部开始找
    .match(Regxp):匹配一个字符串和一个正则表达式
    .replace(searchValue,replaceValue):替换的方法

posted @ 2010-04-08 08:44  云端小飞象cg  阅读(148)  评论(0编辑  收藏  举报