For numbers you can use ES6 Array.from(), which works in everything these days except IE:
Shorter version:
Array.from({length: 20}, (x,i) => i);
Longer version:
Array.from(new Array(20), (x,i) => i);
which creates an array from 0 to 19 inclusive. This can be further shortened to one of these forms:
Array.from(Array(20).keys());
// or
[...Array(20).keys()]];
Lower and upper bounds can be specified too, for example:
Array.from(new Array(20), (x,i) => i + *lowerBound*);
An article describing this in more detail: http://www.2ality.com/2014/05/es6-array-methods.html
For numbers you can use ES6 Array.from(), which works in everything these days except IE:
Shorter version:
Array.from({length: 20}, (x,i) => i);
Longer version:
Array.from(new Array(20), (x,i) => i)
which creates an array from 0 to 19 inclusive. This can be further shortened to one of these forms:
Array.from(Array(20).keys())
// or
[...Array(20).keys()]
Lower and upper bounds can be specified too, for example:
Array.from(new Array(20), (x,i) => i + *lowerBound*)
An article describing this in more detail: http://www.2ality.com/2014/05/es6-array-methods.html
For numbers you can use ES6 Array.from(), which works in everything these days except IE:
Shorter version:
Array.from({length: 20}, (x,i) => i);
Longer version:
Array.from(new Array(20), (x,i) => i);
which creates an array from 0 to 19 inclusive. This can be further shortened to one of these forms:
Array.from(Array(20).keys());
// or
[...Array(20).keys()];
Lower and upper bounds can be specified too, for example:
Array.from(new Array(20), (x,i) => i + *lowerBound*);
An article describing this in more detail: http://www.2ality.com/2014/05/es6-array-methods.html
- 11.1k
- 25
- 118
- 217
For numbers you can use ES6 Array.from(), which works in everything these days except IE:
Shorter version:
Array.from({length: 20}, (x,i) => i);
Longer version:
Array.from(new Array(20), (x,i) => i)
which creates an array from 0 to 19 inclusive. This can be further shortened to one of these forms:
Array.from(Array(20).keys())
// or
[...Array(20).keys()]
Lower and upper bounds can be specified too, for example:
Array.from(new Array(20), (x,i) => i + *lowerBound*)
An article describing this in more detail: http://www.2ality.com/2014/05/es6-array-methods.html
For numbers you can use ES6 Array.from(), which works in everything these days except IE:
Array.from(new Array(20), (x,i) => i)
which creates an array from 0 to 19 inclusive. This can be further shortened to one of these forms:
Array.from(Array(20).keys())
// or
[...Array(20).keys()]
Lower and upper bounds can be specified too, for example:
Array.from(new Array(20), (x,i) => i + *lowerBound*)
An article describing this in more detail: http://www.2ality.com/2014/05/es6-array-methods.html
For numbers you can use ES6 Array.from(), which works in everything these days except IE:
Shorter version:
Array.from({length: 20}, (x,i) => i);
Longer version:
Array.from(new Array(20), (x,i) => i)
which creates an array from 0 to 19 inclusive. This can be further shortened to one of these forms:
Array.from(Array(20).keys())
// or
[...Array(20).keys()]
Lower and upper bounds can be specified too, for example:
Array.from(new Array(20), (x,i) => i + *lowerBound*)
An article describing this in more detail: http://www.2ality.com/2014/05/es6-array-methods.html
For numbers you can soon use the ES6 array feature. Which currently only works in Firefox.Array.from(), which works in everything these days except IE:
Array.from(new Array(20), (x,i) => i)
Would createwhich creates an array from 0 to 19 inclusive. This can be further shortened to one of these forms:
Array.from(Array(20).keys())
// or
[...Array(20).keys()]
Lower and upper bounds can be addedspecified too, for example by:
Array.from(new Array(20), (x,i) => i + *lowerBound*)
An article describing itthis in more precisedetail: http://www.2ality.com/2014/05/es6-array-methods.html
For numbers you can soon use the ES6 array feature. Which currently only works in Firefox.
Array.from(new Array(20), (x,i) => i)
Would create an array from 0 to 19. Lower and upper bounds can be added for example by
Array.from(new Array(20), (x,i) => i + *lowerBound*)
An article describing it more precise: http://www.2ality.com/2014/05/es6-array-methods.html
For numbers you can use ES6 Array.from(), which works in everything these days except IE:
Array.from(new Array(20), (x,i) => i)
which creates an array from 0 to 19 inclusive. This can be further shortened to one of these forms:
Array.from(Array(20).keys())
// or
[...Array(20).keys()]
Lower and upper bounds can be specified too, for example:
Array.from(new Array(20), (x,i) => i + *lowerBound*)
An article describing this in more detail: http://www.2ality.com/2014/05/es6-array-methods.html