Check if a slot exists in a table?

I cannot figure out this simple thing. I am checking to see if something exists in a table:

if (table[“foo”] == “bar”)


If “foo” isn’t set, I get an exception rather then null (or failure to equal “bar”).

How can I just check if there is a foo in bar? I must be missing something simple here!


This should work:

if ("foo" in table && table["foo"] == "bar") { }

Doh! Thanks. I did try that, but I did
foo in table

and of course it failed!