You can use the spread operator on the keys of a freshly created array.
[...Array(n).keys()]
or
Array.from(Array(n).keys())
The Array.from()
syntax is necessary if working with TypeScript
More Related Contents:
- javascript extract certain properties from all objects in array
- Why are Objects not Iterable in JavaScript?
- Create object from array
- Filtering an array with a function that returns a promise
- How to find duplicate values in a JavaScript array of objects, and output only unique values?
- Using Array objects as key for ES6 Map
- Convert ES6 Iterable to Array
- Get list of duplicate objects in an array of objects
- Extract certain properties from all objects in array
- spread operator vs array.concat()
- Unexpected comma using map()
- Replace element at specific position in an array without mutating it
- Find all values by specific key in a deep nested object
- How to create an array of objects from multiple arrays
- Array.from() vs spread syntax
- How to delete property from spread operator?
- Compare two Arrays with Objects and create new array with unmatched objects
- Unable to access React instance (this) inside event handler [duplicate]
- How can I check if the array of objects have duplicate property values?
- Difference and intersection of two arrays containing objects
- Scope of Default function parameters in javascript
- React useState hook event handler using initial state
- How can I reverse an array in JavaScript without using libraries?
- Fastest JavaScript summation
- How do I make a “public static field” in an ES6 class?
- Returning only certain properties from an array of objects in Javascript [duplicate]
- What can we do with ES6 Generator that we cannot with for loop?
- Array.size() vs Array.length
- Sorting an Array of JavaScript Objects a Specific Order (using existing function)
- ES6 module syntax: is it possible to `export * as Name from …`?