Skip to content

Instantly share code, notes, and snippets.

@Arieg419
Last active December 21, 2016 00:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Arieg419/aaa964a5708379f5320f63979acf3250 to your computer and use it in GitHub Desktop.
Save Arieg419/aaa964a5708379f5320f63979acf3250 to your computer and use it in GitHub Desktop.
// create object with numbers as keys
var object = {
1: "First Name",
2: "Middle Name",
3: "Last Name"
};
console.log(object.1); // Uncaught SyntaxError: Unexpected Number
console.log(object."1"); // Uncaught SyntaxError: Unexpected String
console.log(object[1]); // "First Name"
// Iterating through an object to search for Keys
for (key in object) {
console.log(key typeof key); //logs 1..3, "string"
if (key === 1) {
console.log("This is never logged because key is a string.");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment