I have the following code, which doesn't work.
var conversations = { };
conversations['5634576'].name = 'frank';
Apparently I cannot create objects inside objects. I wanted to use the conversation object to store arrays of objects to keep a history of messages client-side with localStorage to save space server side.
But apparently, I cannot even create variables inside the object, unless they already exist, like this:
var conversations = { 123: { name: 'test' } };
conversations[123].name = "frank";
But, since I will not know the IDs that will be used, I have no idea how workaround this problem.
Any ideas?
var conversations = {}; conversations['5634576'] = {}; conversations['5634576'].name = 'frank';, you can check if the second step is necessary usingif (!conversations.hasOwnProperty('5634576')) { /*..*/ }var conversations = { }; conversations['5634576'] = {name: 'frank'}. "what a hassle.": well, what do you expect? You are trying to access the value at property'5634576', which does not exist. Please read MDN - Working with Objects.