继续还是js
中Array
的方法
这次说的方法是from
:https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Array/from
这个方法简单应用如下:
console.log(Array.from('foo'));
// expected output: Array ["f", "o", "o"]
console.log(Array.from([1, 2, 3], x => x + x));
// expected output: Array [2, 4, 6]
我这里写个稍微复杂点的例子,随机生成文件名并排序
[...new Set(Array.from(Array(200).fill('文件'),x=>x+String(parseInt(Math.random()*200)).padStart(3,"0")))].sort()
生成结果: