//属性
Array.prototype.constructor
Array.prototype.length
//方法
//会改变自身的方法
Array.prototype.copyWithin()
Array.prototype.fill()
Array.prototype.pop()
Array.prototype.push()
Array.prototype.reverse()
Array.prototype.shift()
Array.prototype.sort()
Array.prototype.splice()
Array.prototype.unshift()
//不会改变自身的方法
Array.prototype.concat()
Array.prototype.includes()
Array.prototype.join()
Array.prototype.slice()
Array.prototype.toSource()
Array.prototype.toString()
Array.prototype.toLocaleString()
Array.prototype.indexOf()
Array.prototype.lastIndexOf()
//遍历方法
Array.prototype.forEach()
Array.prototype.entries()
Array.prototype.every()
Array.prototype.some()
Array.prototype.filter()
Array.prototype.find()
Array.prototype.findIndex()
Array.prototype.keys()
Array.prototype.map()
Array.prototype.reduce()
Array.prototype.reduceRight()
Array.prototype.values()
Array.prototype[@@iterator]()
reduce
利用reduce检索购物车中商品价格大于10000的商品名称
- let cart = [
- {name:"iphone",price:12000},
- {name:"imac",price:25000},
- {name:"ipad",price:3600}
- ];
- function getGoodsName(goods,price){
- return goods.reduce(function(arr,cur){
- if(cur.price>price)arr.push(cur)
- },[]).map(function(item){
- return item.name
- })
- }
- console.log(getGoodsName(cart,10000))
reduce可以用来检索数组中的最大值
- let arr = [1,2,3,4,5,6,66];
- var max = arr.reduce(function(pre,value){
- return pre>value?pre:value
- })
- console.log(max)
reduce方法去重数组
- let arr = [1,2,2,3,3,3,4,4,5,5];
- arr.reduce(function(arr,cur){
- if(arr.includes(cur) === false){
- arr.push(cur);
- }
- return arr;
- },[])