let example = [];
example.someKey = "hello";
console.log(example); // result: []
console.log(JSON.stringify(example)); // result: []
console.log(example.someKey); // result: hello
console.log(JSON.stringify(example)); // result: []
The reason why you see someKey: 'hello' is because different developer tools interpret objects differently. In the SO snippet tool, as shown, the result is an empty array []. Here's why:
Arrays in JavaScript are actually objects with numeric keys. Since they are treated as objects, they can have properties like your someKey. Adding a property to an array does not add an element (which would require a numeric index). This explains why you may see [someKey: 'hello']. Some consoles use property names and values to display the object for debugging purposes. When you access test.someKey, it accesses only the specific property you requested.
When you use JSON.stringify, it only converts the array elements into the JSON string since you called it on the array itself. This is why you once again see an empty array [] after stringifying it.