📌  相关文章
📜  Javascript函数中的变量名作为字符串 - Javascript代码示例

📅  最后修改于: 2022-03-11 15:03:02.727000             🧑  作者: Mango

代码示例2
var a = [1, 3, 4, 3]
var b = [1, 5, 6, 7]
var c = [3, 4, 8, 9]

function arraySum(x, varName) {
    var sum = 0
    for (let i = 0; i < x.length; i++) {
        sum += x[i]
    }
    console.log("sum of " + varName + " is " + sum)
}

arraySum(a, "a");