The fact is that associative arrays (in which the index can be not only a number, dictionaries) in many languages work with key hashes, and the empty string also has a hash: md5('') == d41d8cd98f00b204e9800998ecf8427e . With the support of this functional problems should not be, as long as this solution fits the meaning of your problem.
For completeness of the answer, we will consider related questions on the use of empty strings as keys:
o = {...} // какой-нибудь объект/словарь o. = 2; // обращение как к полю объекта с пустой строкой не сработает o.'' = 2; // так тоже o[''] = 2; // только как к словарю
Other examples of use:
o[null] // вернёт o['null'] o[undefined] // вернёт o['undefined']
The fact is that null and undefined are special objects in JS, and not some values that have a hash, when translated to a string, they turn into their names. You can convert null and undefined to the empty string '' like this:
key = key || '';
And in order to bring non-string types to a string, you can simply add an empty string:
key = '' + key;
In this case, note that 0 will turn into an empty string '' , while the string '0' remains itself: '0' .
Translation of this answer and some comments.
Опытным путём выяснил, что этот код работает в нескольких браузерахquestion begins with humor. Same syntax, darling, really so didn't know what works? - Goncharov Alexander