Skip to content

Instantly share code, notes, and snippets.

@lemanschik
Last active March 11, 2023 06:50
Show Gist options
  • Save lemanschik/a72a40cbb8a3bfd6bbb8168bae7c65ce to your computer and use it in GitHub Desktop.
Save lemanschik/a72a40cbb8a3bfd6bbb8168bae7c65ce to your computer and use it in GitHub Desktop.
Create a Array of Length and fill it

Examples

Array.from({length: 10},(_v, i) => {});
Array(10).forEach((_v, j) => {});
Object.assign(Array(),{ length: 10 });
Object.assign([],{ length: 10 });

const myArray = [1,2,3,5]
myArray.length = 0; // Ultra fast clear array

Note Array.from is the winner as the most concise api with and without fill

Array.from({length: 10},(_v, i) => {});
Array.from({length: 10});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment