Hi!
I want to store some data in the global context data.
With the help of an import job (.json file > global context storage) I have set up a structure of e.g.:
config.functionNr.200.context
And, yes, the "200" is an object, not part of an array. I can get the data via:
global.get('config.functionNr.200.context');
Now, when I write some new content as context data, using
Honestly, I wouldn't bother trying to get/set deep into the object. Just grab the whole object. I seem to remember we did some tests quite a while ago and came to the conclusion that the whole variable is in memory anyway so there is no advantage trying to only get part of it.
Once you have the whole thing, you can use bracket notation to access via variables.
const myconf = global.get('config')
myconf.functionNr.200.context = value
myconf.functionNr[mynum].context = value
global.set('config', myconf)
You might need to check whether your number is really a number or a string though.
Also note that you should probably try to avoid calling things by names that might already be used such as config and number.
My testing suggested that writing straight to the context property is approx 10% faster than reading the whole context object, then setting a property, then writing the whole context object.
Reading the whole context object then selecting an object property is quicker then reading a single context object property though.
So, evens-stevens then? I have to say that I can never be bothered with the faff of messing around with the selection string and often end up wanting more of the variable anyway so I always just grab the thing and get on with the job. Not very often where a tiny saving would help anyway.