Javascript map/filter/reduce over facebook messenger data
A big inefficiency of the initial approach is that for each person (which is actually a person's name) messages collection will be traversed 4 times.

To significantly optimize the traversal algorithm the current one is substituted with a single loop with multiple conditions per iteration.
All the needed specific counts are declared beforehand and used as accumulators.The Consolidate conditional expression technique is applied based on a common condition m.sender_name === personName.

The final optimized version:

people.forEach((personName) =&gt; {
    let stat = {'name': personName, 'messageCount': 0, 'photoMessageCount': 0, 
               'videoGifMessageCount': 0, 'audioMessageCount': 0};
    messages.forEach((m) =&gt; {
        if (m.sender_name === personName) { 
            stat.messageCount++;
            if (m.photos) stat.photoMessageCount++;
            if (m.gifs || m.videos) stat.videoGifMessageCount++;
            if (m.audio_files) stat.audioMessageCount++;
        }
    });
    stat.richContentMessageCount = stat.photoMessageCount + stat.videoGifMessageCount 
                                   + stat.audioMessageCount;
    stats.push(stat);
});




In case if your stats array is intended to be used only for accumulating statistics from people.forEach(...) iterated once - prefer Array.map approach to create stats array with the results at once:

let stats = people.map((personName) =&gt; {
    let stat = {'name': personName, 'messageCount': 0, 'photoMessageCount': 0, 
               'videoGifMessageCount': 0, 'audioMessageCount': 0};
    // all the logic here
    // ...
    return stat;
});