- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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 an array of first n multiples of an input number in JavaScript
Problem
We are required to write a JavaScript function that takes in two numbers, let say m and n.
Our function should construct and return an array of first n natural multiples of m.
Example
Following is the code −
const m = 6; const n = 14; const firstNMultiple = (m = 1, n = 1) => { const res = []; for(let i = 1; i <= n; i++){ const multiple = m * i; res.push(multiple); }; return res; }; console.log(firstNMultiple(m, n));
Output
[ 6, 12, 18, 24, 30, 36, 42, 48, 54, 60, 66, 72, 78, 84 ]
- Related Articles
- Constructing multiples array - JavaScript
- Constructing an array of addition/subtractions relative to first array element in JavaScript
- Constructing largest number from an array in JavaScript
- Constructing an array of smaller elements than the corresponding elements based on input array in JavaScript
- How to get the first n values of an array in JavaScript?
- How to get only the first n% of an array in JavaScript?
- JavaScript function to take a number n and generate an array with first n prime numbers
- Returning an array containing last n even numbers from input array in JavaScript
- Print first m multiples of n in C#
- Array of multiples - JavaScript
- Return the first duplicate number from an array in JavaScript
- Finding the first non-consecutive number in an array in JavaScript
- Queries for counts of multiples in an array in C++
- Number of vowels within an array in JavaScript
- Constructing product array in JavaScript

Advertisements