This recursive function returns you a string representation of the desired object.
//Usage: getObjectAsString('abc'.split(/\./)) function getObjectAsString (array){ return !array.length ? '{}' : '{"' + array[0] + '":' + getObjectAsString (array.slice(1)) + '}'; }
Now you can convert the output of getObjectAsString to an object using
JSON.parse(getObjectAsString('abc'.split(/\./)))
EDIT : Removed the Input as a String version because it only works for single-letter subparts in the namespace, for example, asked in question (abc), which is usually not the case.
Narendra yadala
source share