JavaScript中数组的函数有哪些-创新互联
JavaScript中数组的函数有哪些?相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。
参数说明
callbackFn 回调函数
thisArg 执行 callbackFn 时使用的 this 值
currentValue 数组中正在处理的元素
index 当前索引
array 源数组
accumulator 累加器
initialValue reduce reduceRight 第一次调用 callbackFn 函数时的第一个参数的值默认值
element 自己实现的 this 对象
forEach 函数
语法:arr.forEach(callbackFn(currentValue [, index [, array]])[, thisArg])
方法功能: 对数组的每个元素执行一次给定的函数。
返回:undefined。
自定义函数:myForEach。
Array.prototype.myForEach = function(callbackFn, thisArg) { if (typeof callbackFn !== 'function') throw ('callbackFn参数必须是函数'); let element = this, len = element && element.length || 0; if (!thisArg) thisArg = element; for (let index = 0; index < len; index++) { callbackFn.call(thisArg, element[index], index, element); } };
标题名称:JavaScript中数组的函数有哪些-创新互联
网站网址:http://tyjierui.cn/article/iojse.html