使用三目运算符太复杂可以试试这种方法! const acc = "one"; let accvalue = 0; const values = { one: 0, two: 1, three: 2, four: 3, five: 5, six: 6, }; accvalue = values[acc] ?? -1; console.log("accvalue", accvalue);