多种方式使用js填充[0, 1, 2, ...., 99]

// 1.使用for循环遍历
    var arr1 = []
    for (var index = 0; index < 100; index++) {
        arr1.push(index)
    }

// 2.使用数组扩展运算符和keys()
    const arr2 = [...Array(100).keys()]

// 3.使用Array.from()
    const arr3 = Array.from(Array(100), (item, index) => index)

// 4.使用map
    const arr4 = [...Array(100)].map((item, index) => index)

 

posted @ 2022-03-28 16:59  Sofiaღ  阅读(179)  评论(0编辑  收藏  举报