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.
Related Contents:
- How can I find and update values in an array of objects?
- How to generate range of numbers from 0 to n in ES2015 only?
- Create object from array
- Filter or map nodelists in ES6
- Why does [NaN].includes(NaN) return true in JavaScript?
- How can I sort an ES6 `Set`?
- spread operator vs array.concat()
- Unexpected comma using map()
- Why are Objects not Iterable in JavaScript?
- Filtering an array with a function that returns a promise
- Convert ES6 Iterable to Array
- Array.from() vs spread syntax
- Converting Object to Array using ES6 features
- How to delete property from spread operator?
- Replace element at specific position in an array without mutating it
- ES6 – Finding data in nested arrays
- How does `Array.from({length: 5}, (v, i) => i)` work?
- How to add multiple classes to a ReactJS Component?
- Array.size() vs Array.length
- Convert array to JSON
- How to scroll to an element?
- Node.js plans to support import/export ES6 (ECMAScript 2015) modules
- How do I zip two arrays in JavaScript?
- Does ECMAScript 6 have a convention for abstract classes? [duplicate]
- Javascript ES6 export const vs export let
- Is this a good way to clone an object in ES6?
- JS/ES6: Destructuring of undefined
- Convert javascript array to string
- Shallow-clone a Map or Set
- Uploading multiple files using formData()
- How do I remove an object from an array with JavaScript? [duplicate]
- How to get the first element of Set in ES6 ( EcmaScript 2015)
- array.select() in JavaScript
- Using jQuery to compare two arrays of Javascript objects
- Array Join vs String Concat
- ES6 import equivalent of require() without exports
- Return index value from filter method javascript
- What’s the difference between “{}” and “[]” while declaring a JavaScript array?
- Using the reduce function to return an array
- How can I push an object into an array?
- React with ES7: Uncaught TypeError: Cannot read property ‘state’ of undefined [duplicate]
- Import not working with JavaScript in PhpStorm/Webstorm
- Idiomatically find the number of occurrences a given value has in an array
- Destructuring array get second value?
- JavaScript – Difference between Array and Array-like object
- Save Async/Await response on a variable
- Inserting if statement inside ES6 template literal
- What is the best way to export an object literal with ES6/2015?
- Sort array by date gives unexpected results
- What is the most efficient way to get the first item from an associative array in JavaScript?