First, the solution:
Obtained by A[key] .
The specific scenario is this:
There is a key of an object is a number, this time using the form of a.b can not get the corresponding value,
Such as:
A. ' 111 ' will cause an error.
Special Note:
a[' 111 '] and a[111] Both are the same, no difference, this usage is the same as the array with subscript access.
another :
When the object's key is a variable and is used in a loop, we can dynamically generate the object by data[' key ', eg:
Summarize:
1. The object's key should generally use a valid variable name (a letter or underscore that begins with a string containing letters, underscores, and numbers), in which case the value can be obtained by a.key or a[' key ').
2. When the special scene key is a number, the corresponding value value can only be obtained by a[' key '.
If you create a map object that corresponds to ID one by one in the database,
You can do the key directly with the ID number, although you can add a letter prefix to it to conform to the standard of the legal variable name,
And let its data be accessed through the Data.key way,
But if the amount of data is very large,
Add a prefix to each ID, and the + character join operation also consumes performance.
Especially in cases where it is seldom necessary to use the Data.key way to access attributes,
Then you can discard this call method, directly with the number of the key is also possible,
There seems to be no other loss except the key name does not conform to the standard of the legal variable name;
Processing when the object key value is a number