Struggling to comprehend the behavior of this particular piece of javascript code.
const devices = searchResult.results.forEach(device => {
const temp = Object.keys(device.fields);
for(var property in temp) {
if(device.fields.hasOwnProperty(property)) {
if (!usedPropertiesAcrossModels.has(property)) {
delete device.fields[property];
}
}
}
}
Attempting to remove keys from a JavaScript object that are not part of a specific set. Despite debugging and confirming only one element in the set and 15 elements in device.fields
, nothing is actually being deleted from device.fields
. It's perplexing! Additionally, temp
appears to be undefined until outside of the loop. The variable property
remains undefined despite there being items in temp. Quite baffling!