Created
January 12, 2019 17:16
-
-
Save 1kohei1/9f68300b86367bdcbe14e8e5e1e58874 to your computer and use it in GitHub Desktop.
This file contains 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
var a = []; | |
a[2] = 1; | |
a.length; // 3 | |
a; // [undefined, undefined, 1] | |
// You can set the key value pair to the array, but it doesn't count in length | |
a.a = 12; | |
a; // [undefined, undefined, a, a: 12]; | |
a.length; // 3 | |
a.a; // 12 | |
// However, if string key can be converted to the base-10 number, it will be conveted and used as a index | |
a['4'] = 4; | |
a.length; // 5 | |
a; // [undefined, undefined, 1, undefined, 4, a: 12] | |
// However, coercion doesn't apply to hexadecimal | |
a['0x00'] = 1; | |
a.length; // 5 | |
a; // [undefined, undefined, 1, undefined, 4, a: 12, 0x00: 1] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment