Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

How to remove key from table
Started by sirmania Apr 03 2018 01:43 AM

4 replies to this topic
key table remove nil

Best Answer nick_sherman , 03 April 2018 - 01:44 AM

playerTable[#playerTable].uselessInfo = nil

[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

sirmania

[GLOBAL: userInfoPane.html]
sirmania
  • Contributor

  • 154 posts
  • Corona SDK

Hi!

A little embarrassing, but I can't figure out how to remove a key from a table  :unsure:

Lets say I create a table like this:

local playerTable = {}

    local params = {
      name = "Rob Miracle",
      age = 29,
      uselessInfo = "Nothing useful",
    }

    playerTable[#playerTable +1] = params

How to remove the key "uselessInfo" from this exact player later?

(I have tables with a lot of players and many params).



[TOPIC: post.html]
#2

nick_sherman

[GLOBAL: userInfoPane.html]
nick_sherman
  • Corona Geek

  • 1,787 posts
  • Corona SDK

  Best Answer

playerTable[#playerTable].uselessInfo = nil


[TOPIC: post.html]
#3

sirmania

[GLOBAL: userInfoPane.html]
sirmania
  • Contributor

  • 154 posts
  • Corona SDK

Ok, nilling out the key solves it, thanks!

 

I feel like deleting this post in embarrassment, but there might be another one missing this obvious solution  :ph34r:



[TOPIC: post.html]
#4

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,660 posts
  • Enterprise

Please leave it.

 

 

Rob



[TOPIC: post.html]
#5

nick_sherman

[GLOBAL: userInfoPane.html]
nick_sherman
  • Corona Geek

  • 1,787 posts
  • Corona SDK

Well, you changed it from uselessInfo to params.....playerTable[1].params doesn't exist so nilling it out does nothing.

 

playerTable[1] becomes whatever params is, it doesn't have params attached to it.

 

 
local function removeKey(table, key)
 
  table[key] = nil
 
end
 
removeKey(playerTable[1], "uselessInfo")
 




[topic_controls]
[/topic_controls]