How to create an array with random values in TypeScript

1 Answer

0 votes
let size: number = 7;

const arr: number[] = Array.from({length: size}, val => Math.floor(Math.random() * 100));

console.log(arr) 



/*
run:

[84, 70, 97, 8, 39, 65, 78] 

*/

 



answered Mar 22, 2024 by avibootz
...