Created
September 19, 2022 04:04
-
-
Save mudssrali/7be1d4c1a4bd6a07e4a77d09dfb7658b to your computer and use it in GitHub Desktop.
Snippets for array generation in JavaScript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// [0, 0, 0] | |
Array(3).fill(0); | |
Array.from(Array(3), () => 0); | |
// [0, 2, 4, 6, 8] | |
Array.from(Array(5), (_, index) => index * 2); | |
// Array of 5 random numbers | |
Array.from(Array(5), Math.random()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment