I'm trying to learn to use Array.from, as I really don't like calling fill and then map
(我正在尝试学习使用Array.from,因为我真的不喜欢先调用fill然后映射)
For example I'm converting
(例如我正在转换)
const tasks = 3
const graph = Array(tasks).fill(0).map(() => Array())
into
(进入)
const graph = Array.from(Array(tasks), () => new Array())
but I get the following error
(但我收到以下错误)
graph[1].push(1)
^
TypeError: Cannot read property 'push' of undefined
I saw on another thread someone post
(我在另一个帖子上看到有人发帖)
var arr = Array.from(Array(2), () => new Array(4));
arr[0][0] = 'foo';
console.info(arr);
And this too throws
(这也抛出)
arr[0][0] = 'foo';
^
TypeError: Cannot set property '0' of undefined
After testing line by line, it appears this line breaks it
(逐行测试后,似乎此行将其中断)
const Deque = require('collections/deque')
Any ideas why https://www.collectionsjs.com breaks the array.from() behavior?
(为什么https://www.collectionsjs.com会破坏array.from()行为?)
ask by FaultyJuggler translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…