I have a function that reads files from a file system and stores them in an array. Subsequently, I want to add a key / value pair to this element. However, the forEach loop is not executed, because apparently there is no element in it.
readFilesFromDirectory(folder, elements, 'json', function(){
log(Object.keys(elements).length,0);
log(elements.length,0);
elements.forEach(function(elem){
elem["newKey"] = 1;
});
});
My log contains the following lines:
1
0
The first length method works, the second does not. I would like to know what I am doing wrong for the second function and how I can fix it.
In fact, my main goal is to add a new key. However, I donβt know how to use some Object.keyValues ββ(elements) .forEach (function (elem) {...} objects in my code. If you have a hint of this, that would be fine too.
I am very grateful for your understanding !:-)