1. Array.map()
let arr = [2, 4, 6, 8];
let newArr = arr.map((value) => {
return value * 2;
});
console.log(arr);
console.log(newArr);
2. Array.forEach()
let arr = [2, 4, 6, 8];
let newArr = [];
arr.forEach((key) =>{
newArr.push(key*2)
})
console.log(newArr);
3. Array.filter()
let arr = [{ name: '李元芳', age: 18 },{ name: '后裔', age: 28 },{ name: '马可波罗', age: 38 }];
let newArr = arr.filter((ele,index) => {
return ele.age > 20
})
console.log(arr);
console.log(newArr);
4. Array.find()
let arr = [{ name: '李元芳', age: 18 },{ name: '后裔', age: 28 },{ name: '马可波罗', age: 38 }];
let newArr = arr.find((item,index) => {
return item.age > 20
})
console.log(newArr);
5. Array.some()
let arr = [1,2,3,4,5,6];
let newArr = arr.some((item,index) =>{
return item > 2
})
console.log(newArr);
6. Array.push()
let arr = [1,2,3]
let newArr = arr.push(4,5)
console.log(arr);
console.log(newArr);
7. Array.pop()
let arr = [1,2,3,4,5]
arr.pop()
console.log(arr);
console.log(arr.length);
8. Array.splice()
let list = [1,2,3];
list.splice(0,1);
console.log(list);
list.splice(0,2);
console.log(list);
list.splice(0,1,4);
console.log(list);
list.splice(0,2,4);
console.log(list);
list.splice(1,0,5);
console.log(list);
9. Array.every()
let arr = [1,2,3,4,5,6];
let newArr = arr.every((item,index) =>{
return item > 2
})
console.log(newArr);
10. Array.concat()
let arr1 = [1, 2, 3]
let arr2 = [4, 5]
let arr3 = arr1.concat(arr2)
console.log(arr3)
11. Array.toString()
let arr = [1,2,3,4,5]
let str = arr.toString()
console.log(arr);
console.log(str);
12. Array.join()
let arr = [1,2,3,4,5]
let arr2 = arr.join('.')
console.log(arr2);
13. Array.shift()
let arr = [1,2,3,4,5]
arr.shift()
console.log(arr);
14. Array.unshift()
let arr = [3,4,5,6,7]
arr.unshift(1,2)
console.log(arr);
console.log(arr.length)
15. Array.indexOf()
var arr = [1,2,3,4,5,6,78];
var newArr = arr.indexOf(3);
console.log(newArr);