Node.js快速生成26个字母

const buf1 = Buffer.allocUnsafe(26);

for (let i = 0; i < 26; i++) {
  // 97 是 'a' 的十进制 ASCII 值。
  buf1[i] = i + 97;
}

console.log(buf1.toString('ascii'));
// 输出: abcdefghijklmnopqrstuvwxyz
console.log(buf1.toString('ascii', 0, 5));
// 输出: abcde
posted @ 2018-12-26 09:59  菜鸟程序员的总结  阅读(459)  评论(0编辑  收藏  举报