- Array
'use strict';
let cout = function(){
console.log('arr1 :'+ arr1);
console.log('arr2 :'+ arr2);
for(let i=0;i<arguments.length;i+=1){
console.log(arguments[i]);
}
}
let arr1 = [1,2,13,15,23];
let arr2 = ['a','b','c'];
let arrCat = arr1.concat(arr2,'d');//c = [ 1, 2, 13, 15, 23, 'a', 'b', 'c', 'd' ]
console.log(arrCat.join());
//返回一个数组中元素组成的字符串,以‘,’隔开
//1,2,13,15,23,a,b,c,d
console.log(arrCat.join(''));
//没有分隔符
//12131523abcd
arrCat.pop();
//删除最后一个元素
//shift 删除第一个元素
arrCat.push(['d','e','f']);
//在末尾添加一个元素
//unshift 在头部添加元素
//[ 1, 2, 13, 15, 23, 'a', 'b', 'c', [ 'd', 'e', 'f' ] ]
var b=arrCat;//引用复制
b.reverse();
//数组反转
console.log(b);
//[ [ 'd', 'e', 'f' ], 'c', 'b', 'a', 23, 15, 13, 2, 1 ]
console.log(arrCat);
//[ [ 'd', 'e', 'f' ], 'c', 'b', 'a', 23, 15, 13, 2, 1 ]
b.sort();//默认转成字符串后排序
//[ 1, 13, 15, 2, 23, 'a', 'b', 'c', [ 'd', 'e', 'f' ] ]
b.sort(function(a,b){
if(a===b){
return 0;
}
if(typeof a === typeof b){
return a<b?-1:1;
}else{
return typeof a < typeof b ? -1 : 1;
}
})
//[ 1, 2, 13, 15, 23, [ 'd', 'e', 'f' ], 'a', 'b', 'c' ]
b.splice(0,2,9,[23,24]);
//第一参数为要删除的下标,第二参数为删除数,后面参数为要在此位置上添加的元素
//b === [ 9, [ 23, 24 ], 13, 15, 23, [ 'd', 'e', 'f' ], 'a', 'b', 'c' ]
let c = b.slice(1,2);
//第一参数为开始截取位置,第二参数为结束截取位置
//c = [ [ 23, 24 ] ]
- Function
Function.apply(thisArg,argArray) Number
Object
Object.hasOwnProperty(name)- RegExp
regexp.exec(string)//返回数组
regexp.test(string)//返回boolean