gpt4 book ai didi

javascript - 如何在javascript中将数字数组中的值相乘?

转载 作者:行者123 更新时间:2023-11-28 14:50:22 26 4
gpt4 key购买 nike

var timeCost =[];
var ride_time = 30;
var cost_per_minute = [0.2, 0.35, 0.4, 0.45];

for (let i = 0; i < cost_per_minute.length; i++ ){
timeCost.push(cost_per_minute[i]*ride_time)
}

console.log(timeCost)

最佳答案

使用 .map() 更加简洁:

let cost_per_minute...
const ride_time = 30;
let timeCost = cost_per_minute.map(x => x * ride_time);

关于javascript - 如何在javascript中将数字数组中的值相乘?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44726687/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com