I am creating a flag game where a random flag is pulled out of an object and the information is stored in a global scope in order to check if the answer given matches the country name associated with the flag.
I would like to delete this property from the object, but can only manage to delete the property if i give the specific property name. But because it is random i dont know the specific property value. Is there a way I can do this with the scope it is stored in?
let randomFlag = () => {
let keys = Object.keys(flags);
if (keys.length > 0) {
const index = Math.floor(keys.length * Math.random());
const key = keys[index];
const value = flags[key];
return {index, key, value}
}
return null;
};
const property = randomFlag(flags);
currentFlag = property.key
document.getElementById('flag').innerHTML = `${property.value}`;
delete flags.currentFlag // This is part is not working unless I write the specific property name.