Arrays Lua:搜索单词-数组中的数组

Arrays Lua:搜索单词-数组中的数组,arrays,lua,Arrays,Lua,我现在正在为Lua编程,而且我对这种语言还很陌生。我遇到了一个问题,我买了一个汽车模型。然后我必须在数组中搜索包含此模型的数组并返回其成本。例如,如果我得到了模型名“zion”,它需要返回它的成本。我真的不知道该怎么做。希望有人能帮我解决 local vehicles = { {name = "Honda Civic", costs = 99000, description = {}, model = "blista2"}, {name = "Peugeot 206 GTI", costs =

我现在正在为Lua编程,而且我对这种语言还很陌生。我遇到了一个问题,我买了一个汽车模型。然后我必须在数组中搜索包含此模型的数组并返回其成本。例如,如果我得到了模型名“zion”,它需要返回它的成本。我真的不知道该怎么做。希望有人能帮我解决

local vehicles = {
{name = "Honda Civic", costs = 99000, description = {}, model = "blista2"},
{name = "Peugeot 206 GTI", costs = 79000, description = {}, model = "blista"},
{name = "Golf R32", costs = 300000, description = {}, model = "zion"},
{name = "Mercedes Brabus", costs = 2000000, description = {}, model = "schafter2"},
{name = "f620", costs = 80000, description = {}, model = "f620"},
{name = "Toyota supra", costs = 290000, description = {}, model = "massacro2"},
}
所以我得到了“锡安”模型,它是第二个阵列。希望您能帮助打印成本=79000的文件,请尝试以下方法:

for k,v in pairs(vehicles) do
    if v.model == "zion" then
        print(v.costs)
    end
end
试试这个:

for k,v in pairs(vehicles) do
    if v.model == "zion" then
        print(v.costs)
    end
end

锡安的成本是300000,而不是79000…是否有一个元素作为关键?(例如:如果每个模型都不同,那么模型可以是关键,您可以重建表车辆)锡安的成本是300000,而不是79000…是否有一个元素作为关键?(例如:如果每个模型都不同,那么模型可以是关键,您可以重建表车辆)