Referencing Object Properties with Numeric Names
Despite the documentation's suggestion that object literal property names can be integers, accessing these properties using the dot syntax (e.g., me.123) fails.
Alternative Syntax: Array-Style Access
To access an object property with an integer name, you must use the array-style syntax:
This syntax behaves as if the property were an element of an array, with 123 being the index.
String Notation
Alternatively, you can use string notation to access the property:
This approach encloses the integer in double quotes, treating it as a string.
Example:
In your example, you can access the property with integer name 123 using:
console.log(me[123]); // Output: 26
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3