Hello folks. I have a question about a use of sharedArray that is giving me grief…
given this datafile seed_data.json…
{
"rampup_peak":
[
{
"key": "4m",
"weight": 1
}
],
"duration_peak": [
{
"key": "14m",
"weight": 1
}
]
}
when I try to access the file with SharedArray in the follow way
let KEY = 'rampup_key'
const seed_file = new SharedArray('Accounts', function () {
return JSON.parse(open('../../data/seed_data.json')).KEY;
});
I get this error
/\ |‾‾| /‾‾/ /‾‾/
/\ / \ | |/ / / /
/ \/ \ | ( / ‾‾\
/ \ | |\ \ | (‾) |
/______ \ |__| \__\ \_/ .io
TypeError: Cannot read property 'KEY' of undefined
here’s my current silly question… is a global variable KEY not accessible within a javascript function return? KEY is clearly defined but the variable is out of scope within the SharedArray function to open the file and access the JSON within.
Doesn’t appear to be a SharedArray issue. just whether a variable can used to represent a KEY within a JSON object.
this returns undefined as well.
let keys = JSON.parse(open('../../data/seed_data.json')).$KEY;
let data_key = JSON.stringify(rampup_peak[0].key)