Strange object element behavior with node.js

I am currently trying to set properties of an object using square bracket notation. The code looks like this

var obj = {};
obj['c9c4d17a698ace65c80416112da3ff66e652ec013222f5b458a1dd4950580e77'] = 'one';
obj['8d207abeb95e36abfa2cdae6ac700e776c982ec64bcbfd501cb48fec55a13a77'] = 'two';

      

If you then do console.log(obj)

or console.dir(obj)

, the result is

{ c9c4d17a698ace65c80416112da3ff66e652ec013222f5b458a1dd4950580e77: 'one',
'8d207abeb95e36abfa2cdae6ac700e776c982ec64bcbfd501cb48fec55a13a77': 'two' }

      

I want to know why one property key is specified as an unquoted literal and the other as a string. They both install the same way. Am I falling victim to some kind of escape sequence inside a key?

node --version

v0.10.33

on OS X Yosemite 10.10.1

+3


source to share


1 answer


Every time your object key starts with a number, it is displayed as specified when checked in the console.



This does not affect the internal presentation. These keys are always strings assigned. It's just that when you check them, they will only be listed if they should be (for example, when they contain a reserved character or start with a number).

+2


source







All Articles