Why do we use `Number.prototype.valueOf` inside of a `map()` function

后端 未结 3 1109
时光说笑
时光说笑 2021-01-17 07:21

The following code:

let resultsArray = Array.apply(null, Array(10)).map(Number.prototype.valueOf,0);

creates the following array

         


        
3条回答
  •  一个人的身影
    2021-01-17 07:46

    There is another solution

    Array.from(new Array(10), () => 0)
    

    Ad if your browser does not support ES6, then

    Array.from(new Array(10), function(){return 0;})
    

提交回复
热议问题