- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Writing table of number in array in JavaScript
We are required to write a JavaScript function that takes in two numbers, say m and n, and it returns an array of first n multiples of m.
Therefore, let’s write the code for this function −
Example
The code for this will be −
const num1 = 4; const num2 = 6; const multiples = (num1, num2) => { const res = []; for(let i = num1; i <= num1 * num2; i += num1){ res.push(i); }; return res; }; console.log(multiples(num1, num2));
Output
The output in the console will be −
[ 4, 8, 12, 16, 20, 24 ]
Advertisements