Last active
December 21, 2016 00:10
-
-
Save Arieg419/aaa964a5708379f5320f63979acf3250 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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