• 请不要在回答技术问题时复制粘贴 AI 生成的内容
MajestySolor
V2EX  ›  程序员

有 Lua 大佬在么,问个低端问题。

  •  
  •   MajestySolor · Jun 9, 2022 · 1707 views
    This topic created in 1445 days ago, the information mentioned may be changed or developed.

    关于使用table.insert向表里插入新值的方法

    正常情况下比如有这样一个表

    local list = {apple, banana, peach}
    

    然后插入,这样的我懂

    table.insert(list, "grapes"}
    

    但是假如有这样一个表

    local list = {
    	["apple"] = true,
    	["banana"] = true,
    	["peach"] = true,
    }
    

    应该如何使用table.insert插入以下内容?

    "grapes" = true
    
    3 replies    2022-06-09 20:37:24 +08:00
    Joey2022
        1
    Joey2022  
       Jun 9, 2022   ❤️ 1
    list.grapes = true
    changnet
        2
    changnet  
       Jun 9, 2022   ❤️ 1
    list.grapes = true 或者 list["grapes"] = true
    MajestySolor
        3
    MajestySolor  
    OP
       Jun 9, 2022
    @Joey2022 @changnet 感谢两位
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   880 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 40ms · UTC 19:49 · PVG 03:49 · LAX 12:49 · JFK 15:49
    ♥ Do have faith in what you're doing.