map
源码
/**
* 创建一个数组, value(值) 是 iteratee(迭代函数)遍历 collection(集合)中的每个元素后返回的结果。
* iteratee(迭代函数)调用3个参数: (value, index|key, collection).
*
* @since 5.0.0
* @category Array
* @param {Array} array 用来迭代的集合。
* @param {Function} iteratee 每次迭代调用的函数。
* @returns {Array} 返回新的映射后数组。
*/
function map(array, iteratee) {
let index = -1;
const length = array == null ? 0 : array.length;
const result = new Array(length);
while (++index < length) {
result[index] = iteratee(array[index], index, array);
}
return result;
}知识点
相关链接
Last updated