Array数组操作

对原数组进行操作

Array.prototype.reverse()

myArray.reverse();
复制代码

Array.prototype.shift()

myArray.shift();
复制代码

Array.prototype.unshift()

myArray.unshift(element1, ..., elementN);
复制代码

Array.prototype.splice()

myArray.splice(start, deleteCount, item1, item2, ...);
复制代码

String.prototype.split()

var newArray=str.split([separator[, limit]]);
复制代码

返回新数组,不改变原数组

Array.prototype.slice()

var newArray=array1.slice(begin, end);
复制代码

Array.prototype.concat()

var newArray=array1.concat(array2);      //array1在前
复制代码

Array.prototype.filter()

var newArray=array1.filter(value => value >= 10);  
复制代码

Array.prototype.map()

var newArray = array1.map( x => x ** 2)
复制代码

Array.prototype.reduce()

var number=array1.reduce((accumulator, currentValue) => accumulator + currentValue)
复制代码

Array.prototype.join()

var string=array1.join();
复制代码

Array.prototype.reduce()

var number=array1.reduce((accumulator, currentValue) => accumulator + currentValue);
复制代码

Array.prototype.indexOf()

var num=array1.indexOf(searchElement[, fromIndex = 0])  //没有找到返回-1,找到返回索引
复制代码

mozilla

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值