一、找出元素item在给定数组arr中的位置,否则返回-1
![](https://upload-images.jianshu.io/upload_images/13366813-3ffc043a4fd4601d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
查找元素位置的健壮代码
二、计算给定的数组元素总和(元素均为Number类型)
方法有很多种,常规的循环,递归,forEach遍历,reduce累加甚至是eval()也可以
![](https://upload-images.jianshu.io/upload_images/13366813-d8e0d2d702de18b5.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
reduce是专门为累加而生的
三、复制数组
![](https://upload-images.jianshu.io/upload_images/13366813-84f9fe2ce0a24fdc.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
slice(0)方法是最为简便的
四、不修改原数组,删除与数组值相同的指定元素
![](https://upload-images.jianshu.io/upload_images/13366813-55ac8bc9f14f980c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
在不修改原数组的情况下,最简便的方法就是使用fliter返回过滤后的数组
*在上面的方法中,push方法与splice方法都会修改调用的数组本身,假若本题改为直接修改,则不需要复制原数组再执行操作。
五、在数组后面添加元素,不直接修改数组
![](https://upload-images.jianshu.io/upload_images/13366813-813bf6151e7e8672.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
六、删除最后一个元素,不直接修改数组
![](https://upload-images.jianshu.io/upload_images/13366813-09704b5c19a9ea60.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
七、合并数组,不直接修改数组
![](https://upload-images.jianshu.io/upload_images/13366813-0104dabd85a5fb70.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
八、统计数组中指定item出现的次数
![](https://upload-images.jianshu.io/upload_images/13366813-b3e8b3056fd04001.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
九、查找重复元素
![](https://upload-images.jianshu.io/upload_images/13366813-0ec740733deeea29.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
十、求二次方
![](https://upload-images.jianshu.io/upload_images/13366813-4b5f55722fe79aea.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
十一、在数组 arr 中,查找值与 item 相等的元素出现的所有位置
![](https://upload-images.jianshu.io/upload_images/13366813-c009e94b229caaf0.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)