I need to create an array of variable length where each element is a unique symbol. Is there a built-in (ES6) or lodash method to easily do this? What I have currently is _.map(range(n), () => Symbol())
which is fairly efficient text and timewise, but I would prefer to replace map
with a different function that allows me to replace range(n)
with just n
.
Array.from({length: n}, () => Symbol())
将是一种选择。
您可以使用时间 :
let result = _.times(5, () => Symbol())
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.