You cannot use arbitrary indexes in an array, but you can use an object literal to (sort) the execution of what you are after:
var test = {}; test[false] = "asdf"; test['false'] = "fdsa";
However, it should be noted that object properties must be strings (or types that can be converted to strings). Using a logical primitive will simply end up creating an object property called 'false' .
test[false] === test['false'] === test.false
This is why your first example Object.keys().length only calls 1 .
For an excellent guide to getting started with objects in JavaScript, I would recommend MDN Working with Objects .
source share