I'm trying to store an array of objects , with each object containing an array and an index (called 'column'). the column is string that looks like
'0:lubbock:LW8-12$'
In the main file I am calling:
const tbdObj = await myFunctions.getFromStorageBy(mycolumn);
I want to search through the json in the file 'storage.json' for the object that matches the index (there should be only 1).
async function getFromStorageBy(index) {
let match;
fs.readFile("storage.json", function (err, data) {
// Display the file content
// console.log(index);
const jsonArray = JSON.parse(data);
const matches = jsonArray.filter(obj => obj.column == index);
console.log('matches');
console.log(matches);
match = matches.pop();
console.log(match);
});
return match;
}
The program appears to skip over the readfile block and match is undefined when I try to return it. What am I doing wrong?