Languages
[Edit]
EN

TypeScript - generate array with 10 random numbers

0 points
Created by:
Palus-Bear
1016

In this article, we would like to show you how to generate an array with 10 random numbers in TypeScript.

Quick solution:

Note:

Use Math.floor() to get integers instead of float numbers. You can find practical examples in the sections below.

1. Using Array.fill() with map() method

Edit

In this example we take the following steps:

  1. Create an array with size 10,
  2. Use fill() method to fill the array with specified values,
  3. use map() method to call Math.random() to generate a random value for each element in the array (from 0-50 exclusive).

Practical example:

If you want to receive integers instead of float numbers use Math.floor() method:

Practical example:

1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join