- 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
Constructing multiples array - 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.
For example −
If the numbers are 4 and 6
Then the output should be −
const output = [4, 8, 12, 16, 20, 24]
Example
Following is the code −
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
This will produce the following output on console −
[ 4, 8, 12, 16, 20, 24 ]
Advertisements