如何将数组的每个成员乘以JavaScript中的可变标量?
我正在编写一个代码,该代码将数组中的每个项目乘以可变标量(2 ** i)
a=[1, 2, 3, 4]
for (let i=0; i<a.length; i++) {
let output = //
}
console.log(output) // **output = [1*(2**0), 2*(2**1), 3(2**2), 4(2**3)]**
I'm writing a code that multiply each item in array with a variable scalar ( 2**i)
a=[1, 2, 3, 4]
for (let i=0; i<a.length; i++) {
let output = //
}
console.log(output) // **output = [1*(2**0), 2*(2**1), 3(2**2), 4(2**3)]**
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
地图
与以下方式相同You can use
map
same as :只需从for创建一个数组并推动值即可。
Just create an array out of the for and push the values.