gpt4 book ai didi

javascript - depName 未定义

转载 作者:行者123 更新时间:2023-11-29 19:09:06 25 4
gpt4 key购买 nike

它告诉我 depName 是未定义的。我正在尝试迭代,只是可以看到它有什么问题。我正在尝试从数组中获取最赚钱的部门。

var salesData = [
{department : 'hardware', sales : 4500, day : 'Monday'},
{department : 'outdoor', sales : 1500, day : 'Monday'},
{department : 'carpentry', sales : 5500, day : 'Monday'},
{department : 'hardware', sales : 7500, day : 'Tuesday'},
{department : 'outdoor', sales : 2505, day : 'Tuesday'},
{department : 'carpentry', sales : 1540, day : 'Tuesday'},
{department : 'hardware', sales : 1500, day : 'Wednesday'},
{department : 'outdoor', sales : 8507, day : 'Wednesday'},
{department : 'carpentry', sales : 8009, day : 'Wednesday'},
{department : 'hardware', sales : 12000, day : 'Thursday'},
{department : 'outdoor', sales : 18007, day : 'Thursday'},
{department : 'carpentry', sales : 6109, day : 'Thursday'},
{department : 'hardware', sales : 7005, day : 'Friday'},
{department : 'outdoor', sales : 12006, day : 'Friday'},
{department : 'carpentry', sales : 16109, day : 'Friday'},
];

var depMap = {};
function mostProfitableDepartment() {
for (var i = 0; i < depName.length; i++) {
var currentDep = depName[i]
}
console.log(currentDep);
}
mostProfitableDepartment(salesData);

最佳答案

您在函数声明中遗漏了名称

function mostProfitableDepartment(depName) {

关于javascript - depName 未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40525500/

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