1.splice:向数组中可删除从index处开始的零个或多个元素,返回删除之后的数组。删除从这个下标开始的两个元素,并添加一个元素,代替删除的元素。
var arr=[];arr[0] = "George"arr[1] = "John"arr[2] = "Thomas"arr[3] = "James"
arr[4] = "Adrew"arr[5] = "Martin"
arr.splice(1,2,"aa");
2.ES6数组去重。
(1).const s=new Set();
let Arrys=[2,3,3,4,5];
Arrys.forEach(x=>s.add(x);
for(let i of s){
console.log("i",i);
}
(2).var arr = [{
"name": "ZYTX",
"age": "Y13xG_4wQnOWK1QwJLgg11d0pS4hewePU95UHtpMl3eE81uS74NC-6zu-Rtnw4Ix",
"gender": "AAAAAA.doc"
}, {
"name": "ZYTA",
"age": "Y13xG_4wQnOWK1QwJLgg11d0pS4hewePU95UHtpMl3eE81uS74NC-6zu-Rtnw4Ix",
"gender": "BBBBBB.doc"
},{
"name": "ZYTX",
"age": "Y13xG_4wQnOWK1QwJLgg11d0pS4hewePU95UHtpMl3eE81uS74NC-6zu-Rtnw4Ix",
"gender": "AAAAAA.doc"
}];
var hash = {};
arr = arr.reduce(function(item, next) {
hash[next.name] ? '' : hash[next.name] = true && item.push(next);
return item
}, [])
console.log(arr);
(3).filter过滤器。
filter的callback函数需要返回true或false,如果为true则表示通过;如果为false,抛弃。
let arrys=[0,1,2,3];
let arry= arrys.filter((item, index) => {
return item;
});