摘要: js中的数组遍历是项目中经常用到的,在这里将几种方法做个对比。 ! for循环:使用评率最高,也是最基本的一种遍历方式。 let arr = ['a','b','c','d','e']; for (let i = 0, len = arr.length; i < len; i++) { consol 阅读全文
posted @ 2019-01-31 10:51 Webwhl 阅读(248) 评论(0) 推荐(0) 编辑
摘要: //ES5合并数组 var arr = [12,true,5]; var arrCont = [1,6,66].concat(arr); console.log(arrCont);//[1, 6, 66, 12, true, 5] //ES6 var arr = [12,true,5]; var a 阅读全文
posted @ 2019-01-31 10:42 Webwhl 阅读(754) 评论(0) 推荐(0) 编辑
摘要: function f(){ var a = Array.prototype.slice.call(arguments);//传的参数转为数组 var sum= 0; a.forEach(function(item){ sum+=item*1; }) return sum } console.log( 阅读全文
posted @ 2019-01-31 10:35 Webwhl 阅读(1969) 评论(0) 推荐(0) 编辑