I'm trying to add a key to an object if it doesn't exist, or increase its count if it's already present. The following code correctly adds the new key if it doesn't exist, but doesn't increase its count if it already does. Instead it returns {UniqueResult1:NaN, UniqueResult2:NaN}.
let detectionHash = {};
function onDetected(result) {
detectionHash[result.code]++;
if(detectionHash[result.code] >= 5) {
//here's where I want to be
}
}
How can I increase the count of the key if it already exists?