在 JavaScript 中编写数组中的数字表
javascriptweb developmentfront end technologyobject oriented programming更新于 2026/2/9 6:04:17
我们需要编写一个 JavaScript 函数,该函数接受两个数字,即 m 和 n,并返回 m 的前 n 倍数的数组。
因此,让我们编写该函数的代码 −
示例
其代码为 −
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));
输出
控制台中的输出将是 −
[ 4, 8, 12, 16, 20, 24 ]
相关文章
有用资源
javascript 参考教程 - 该教程包含有关 javascript 的更多信息:https://www.cainiaomax.com/javascript/

