How to count occurrence of unique keys from multiple objects in Javascript?

There are multiple objects that I extracted from multiple json files. Through iteration, I then transformed each json file into an object that contains unique key value pairs. The goal is to make a new object that has count occurrence of each unique key among all objects. My issue is it keeps counting each object multiple times (the total numbers of the objects) instead of just once.

pseudo code as below:

//method of counting occurrence of unique keys

const totalCounts = (obj) => {
  let sum = 0;
  let result = {};
  for (let el in obj) {
    if (obj.hasOwnProperty(el)) {
      sum += parseFloat(obj[el]);
      result[el] = sum;
    }
  }
  return result;
};

//extract json files then transform each file into an array of objects
    files.forEach(fileName, i){
        const arrayOfObj = json.keyName;
        let occurrence = arrayOfObj.reduce(
            (acc, o) => ((acc[o.uniqueKey] = (acc[o.uniqueKey] || 0) + 1), acc),
            {},
          );
      //count occurrences of all unique keys among all the arrays of objects

const output = totalCounts(occurrence);
//some logic to pass the output variable to make a new object that has the total occurrence for all objects.
    }

My issue I think is a scope problem essentially that I’m struggling with. I know the occurrence variable is what I need to use for the end result and it caused duplicated iterations because the logic lives inside of the loop instead of outside. Could anyone give me some pointers about how to debug this problem?

What I want is an output like:

{key1: 3, key2: 5, ....}

What I got so far is:

{key1: 33, key2:25 ...}, { key1: 12, key2: 3...}, ....30 more objects