How to generate sequence of numbers/chars in javascript?

前端 未结 18 1213
被撕碎了的回忆
被撕碎了的回忆 2020-12-13 06:22

Is there a way to generate sequence of characters or numbers in javascript?

For example, I want to create array that contains eight 1s. I can do it with for loop, bu

18条回答
  •  情书的邮戳
    2020-12-13 06:53

    Using Jquery:


    $.map($(Array(8)),function(val, i) { return i; })
    

    This returns:

    [0, 1, 2, 3, 4, 5, 6, 7]
    

    $.map($(Array(8)),function() { return 1; })
    

    This returns:

    [1, 1, 1, 1, 1, 1, 1, 1]
    

提交回复
热议问题