Question on how to remove a key-value pair from a dictionary

Say I had this:

local fruits = {
    apple: "Red",
    banana: "Yellow"

How would you remove a key-value pair from fruits? Do you just set a key’s value to nil? Is there a remove function designed for dictionaries?

1 Like

You can remove a key/value pair with table.remove. More on that here

My concern is that those functions are designed for an array/table. I don’t know if it works the same with dictionaries.

Nevermind, I found this article that solves my problem.


That doesn’t work, just do fruits[apple] = nil. The PiL link you posted mentions this:

The table.remove function removes (and returns) an element from a given position in an array


1 Like

Yep! I was replying to Cyafu, clarifying that these won’t work at all. You said you didn’t know, so I felt it was best to clarify.


Oh, sorry for the confusion. I thought you were talking to me. :sweat_smile: