One can create an empty array, fill it (otherwise map will skip it) and then map indexes to values:
Array(8).fill(0).map((_, i) => i * i);
More Related Contents:
- Methods in ES6 objects: using arrow functions
- One-liner to take some properties from object in ES 6
- When should I use arrow functions in ECMAScript 6?
- What is the motivation for bringing Symbols to ES6?
- How can I clone a JavaScript object except for one key?
- Is there a mechanism to loop x times in ES6 (ECMAScript 6) without mutable variables?
- Merge two arrays with alternating values
- JavaScript ES6: Test for arrow function, built-in function, regular function?
- Immediate function using JavaScript ES6 arrow functions
- Function parameter definitions in ES6
- What can we do with ES6 Generator that we cannot with for loop?
- Is it possible to reset an ECMAScript 6 generator to its initial state?
- user defined object equality for a set in harmony (es6)
- What’s the meaning of “=>” (an arrow formed from equals & greater than) in JavaScript?
- What is destructuring assignment and its uses?
- Arrow function without curly braces
- ES6 class variable alternatives
- What are the differences (if any) between ES6 arrow functions and functions bound with Function.prototype.bind?
- How do I destructure all properties into the current scope/closure in ES2015?
- How can I mock an ES6 module import using Jest?
- Unexpected behavior using Array Map on an Array Initialized with Array Fill
- Why are Promises Monads?
- Define a custom hash() method for use with ES6 maps
- How to import part of object in ES6 modules
- Web Workers – How To Import Modules
- Template literals with nested backticks(`) in ES6
- JavaScript asynchronous programming: promises vs generators
- Unnecessary ‘else’ after ‘return’. (No-else-return)
- ES6 arrow function and lexical scope inside a function [duplicate]
- ESLint: “error Parsing error: The keyword ‘const’ is reserved”