Skip to content

Instantly share code, notes, and snippets.

@cyio
Created September 22, 2016 09:42
Show Gist options
  • Save cyio/aebd1c2cabe4b3daa4a366d92724aed5 to your computer and use it in GitHub Desktop.
Save cyio/aebd1c2cabe4b3daa4a366d92724aed5 to your computer and use it in GitHub Desktop.
快速创建成员为0-9的数组,等价的两种方式
// 快速创建成员为0-9的数组,等价的两种方式
// let arr = []
// arr.length = 10
let arr = new Array(10) // 参数为个位数,表示长度,否则表示成员
//let arr = new Array(0, 1, 2)
for (let i=0; i<arr.length; i++) {
arr[i] = i
}
console.log(arr) // [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment