Easy way to set javascript object multilevel property?

javascript, json, key-value, object

Solution

No, there is no way to set "multilevel keys". You need to initialize each object before trying to add properties to it.

var allUserExpiry = {};
allUserExpiry[aData.userId] = {}
allUserExpiry[aData.userId][aData.courseId] = {}
allUserExpiry[aData.userId][aData.courseId][aData.uscId] = aData;

Problem

I am trying to create a javascript object like ``` var allUserExpiry={}; allUserExpiry[aData.userId][aData.courseId][aData.uscId] = aData; ``` But I am getting an error like `allUserExpiry[aData.userId]` undefined. Is there a way, whereby I can set multi-level JS-Object keys? or is it important that I should go by doing `allUserExpiry[aData.userId]={}`, then `allUserExpiry[aData.userId][aData.courseId]={}` ? Please let me know if there are any utility functions available for the same.

Original source