Throughout my coding journey, I've always used:
var j= {};
j['field'] = value;
It turns out the following also works:
var j= [];
j['field'] = value;
Is there any difference between the two?
Edit: Apologies for using the wrong term "json" instead of object. My mistake. However, my question remains the same. Most people are explaining the distinction between an array and object, which I already understand.
I typically use var x = []; x.push('blah') etc.
I also use var x = {}; x.Name = 'Michael'; x.Age = 21 etc.
What caught my attention was seeing code like var x = []; x.name = 'Michael';
This was new to me, so I decided to ask about it.
Thank you to everyone who provided answers. I have marked the accepted answer that best addressed my inquiry.