Search for an item in a Lua list

后端 未结 10 2440
青春惊慌失措
青春惊慌失措 2020-11-29 00:56

If I have a list of items like this:

local items = { \"apple\", \"orange\", \"pear\", \"banana\" }

how do I check if \"orange\" is in this

10条回答
  •  广开言路
    2020-11-29 01:20

    Use the following representation instead:

    local items = { apple=true, orange=true, pear=true, banana=true }
    if items.apple then
        ...
    end
    

提交回复
热议问题