Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
327 views
Welcome To Ask or Share your Answers For Others

1 Answer

The ...(spread operator) works by returning each value from index 0 to index length-1:

As example:

[...'18'] // returns ['1', '8']

which would be the same as:

['18'[0], '18'[1]]

Now, to get an array from 1 to 18, you can do this:

[...Array(19).keys()].slice(1)

Or this with map:

[...Array(18)].map(_=>i++,i=1)

Hope it helps.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...