The "in" operator


#1

On the Squirrel Programming Guide (https://electricimp.com/docs/squirrel/squirrelcrib/), there is this example:

if (firstKey in myTable) {
// ‘myTable’ has the key ‘firstKey’ so set it
myTable.firstKey = “Rowdy Yates Block”;
}

I get this error: the index ‘firstKey’ does not exist. I have to put quotes around firstKey for this to work: if (“firstKey” in myTable) {

Is this a documentation error or am I missing something?


#2

Yeah, that would appear to be a documentation error. It should be quoted, as you have it. Unless, of course, you had:

local keyName = "firstKey"; if (keyName in myTable) { /* ... */ }

I’ll alert the documentation team.


#3

Documentation updated! Thanks for the find, @Kitty.