Test for an index in table before using it

I am getting an exception when I try to check the value stored in a table that I read from the NV area. This is because it may not yet contain the new slot index that I have added. Is there a way to read what indexes are available in the table before using them?

Never mind. I found it in the squirrel documentation under “in operator.”

if ("slot_name" in tableName) { if (tableName["slot_name"] == desired_value) { <do stuff> } }

@cybi-buildmgr: I wrapped your code in < code ></ code > tags to make formatting work :slight_smile:

Once you know a slot exists (using the in keyword) - you can also access it with tableName.slowName:

if ("slot_name" in tableName) { if (tableName.slot_name == "someVal") { } }

If slot_name doesn’t have any spaces, you can just use:

if ("slot_name" in tableName) { if (tableName.slot_name==desired_value) {...

whoops! @beardedinventor, you beat me to it!