标签:filter 过滤 slice art 映射 开始 function join() val
function map(){
var arr = [1,2,3,4,5];
arr.map(function(val,index){
console.log(val * 2);
})
}
//map(); //2 4 6 8 10
function filter(){
var arr = [1,2,3,4,5,6,7];
var arr1 = arr.filter(function(val,index){
return val < 4 ;
})
console.log( arr1 ); //[1,2,3]
var arr2 = arr.filter(function(val,index){ //定义一个变量名接一下
return index < 3;
})
console.log( arr2 ); //[1,2,3]
}
//filter();
//var arr = [‘a‘,‘b‘,‘c‘,‘d‘,‘e‘,‘f‘]
//var arr1 = arr.filter(function(val,index){
//return index < 3;
//})
//console.log(arr1)
function push(){
var arr = [1,2,3];
arr.push(2,3,4);
console.log(arr);
}
//push(); //[1,2,3,2,3,4]
function push2(){
var arr1 = [1,2,3];
var arr2 = [4,5,6];
arr1.push( arr2 );
return arr1;
}
console.log( push2() ) //[ 1,2,3,[4,5,6] ]
function unshift(){
var arr=[1,2,3];
arr.unshift(4,5,6);
console.log(arr); //[4, 5, 6, 1, 2, 3]
}
//unshift();
function pop(){
var arr = [1,2,3];
arr.pop();
console.log(arr); //[1,2]
}
//pop();
function shift(){
var arr = [1,23,4];
arr.shift();
console.log(arr); //[23,4]
}
//shift();
function concat(){
var arr1 = [1,2,3];
var arr2 = [4,5,6];
console.log( arr1.concat(arr2) ) //[1, 2, 3, 4, 5, 6]
console.log( arr1.concat(1,2,3)) //[1, 2, 3, 1, 2, 3]
}
//concat();
function reverse(){
var arr = [1,2,3,4,5,6,7,8];
console.log( arr.reverse() ) //[8, 7, 6, 5, 4, 3, 2, 1]
}
//reverse();
function slice(){
var arr = [1,2,3,4,5,6];
console.log( arr.slice(0,4) ); //[1, 2, 3, 4]
}
slice();
function splice(){
var arr = [1,2,3,4,5,6,7];
console.log( arr.splice(0,3) ); //[1,2,3]
}
//splice();
function join(){
var arr = [1,2,3,4,5,6,7];
return arr.join("|");
}
//console.log( join() ) //"1|2|3|4|5|6|7"
function join2(){
var arr = [1,2,3,4,5];
arr.join();
return arr.join().slice(0,3);
}
//console.log( join2() ) //1,2
标签:filter 过滤 slice art 映射 开始 function join() val
原文地址:http://www.cnblogs.com/lhh-bky/p/7992841.html