The key value of
object is a string, b and c are both the same object. If you take them as the key value of a, you will first convert them into a string. After the object is converted into a string, it is [object Object]
, so a [b] = 123 is a [[object Object]'] = 123, and execute a [c] = 345. The a [[object Object]'] will be re-assigned to 345, so printing a [c] and a [d] is the value of a [[object Object]'], and the result is 345
.
When
array d is converted into a string, the result is 3 code 5 code >, so a [d] = 333; that is, a ['3jue 5je 6'] = 333 *. The same way to take the value is to take the value
of a ['3jue 5jue 6'].
< H2 > add < / H2 >
Symbol types available as object properties in es6
Object built-in toString and valueOf methods;
in this case a [b] = 123 will call the object's toString ().
a [b] = 123, that is, a [[object Object]'] = 123
a [c] will lead to toString () and a [[object Object]'] = 345;
and the array toStirng () ='[object Array]';
the final a should be {'[object Object]': 345 object Array'[object Array]
what happens when ps: calls toString () by default? I'll check it first.
is wrong. It should be a {'[object Object]': 345, 5, 5, 5, 6, 3, 3, 3, 3, 3, 3, 3, 5, 5, 6, 6, 3, 3, 3, 3, 3, 3, 3, 3
The key of
JS ordinary object can only be a string. If you want to use a variable as a key, you can use Map
.
the previous boss is right