Array.apply(null,{length:6}).map()

map定义和方法 
map()方法返回一个新数组,数组中的元素为原始数组元素调用函数处理的后值。 
map()方法按照原始数组元素顺序依次处理元素。 
注意: 
map不会对空数组进行检测 
map不会改变原始数组 
arr.map(function(currentValue,index,arr),thisValue) 
参数说明 
function(currentValue,index,arr) 
必须,函数,数组中的每个元素都会执行这个函数函数参数 
函数参数 
currentValue 必须 当前元素值 
index 可选 当前元素的索引值 
arr 可选 当前元素属于的数组对象。

Array.apply(null, { length: 5 }) 和 Array(5)有什么不同

注意:ES5,apply函数的第二个参数除了可以是数组外,还可以是类数组对象

// 类转成真正的数组
var a = Array.prototype.slice.call({length: 2});
Array.apply(null, { length: 5 })
// 结果 [undefined, undefined, undefined, undefined, undefined]

Array(5)
//结果 [empty × 5] => [,,,,]

为什么要这么写

map函数并不会遍历数组中没有初始化或者被delete的元素(有相同限制还有forEach, reduce方法)。
Array.apply(null, { length: 5 }) 是用来初始化一个长度为5,每项的初始值都是undefined的数组

    render (createElement) {
      return createElement('div',
        Array.apply(null, { length: 20 }).map(function () {
          return createElement('p', 'hi')
        })
      )
    }
 

---------------------
原文:

https://blog.csdn.net/weixin_40475396/article/details/79186238 

https://www.cnblogs.com/yangwang12345/p/7729194.html

原文地址:https://www.cnblogs.com/wanlibingfeng/p/10057660.html