Created
September 22, 2016 09:42
-
-
Save cyio/aebd1c2cabe4b3daa4a366d92724aed5 to your computer and use it in GitHub Desktop.
快速创建成员为0-9的数组,等价的两种方式
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 快速创建成员为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