You should not use variable i as index for contArr variable, because each time you have a new event data, i is reseted to 0.
I would have done something like this:
var allContinents = {}; // this is an object, not an array
socket.on('data', function(data) {
//iterate through the socket data
data.forEach(function (item, i){
//get current continent name
var continent = item.continent;{
if (!(item.continent in allContinents))
{
// we create the object if it doesn't exist yet
// the object key is the contient name...
allContinents[item.continent] = {
continent: continent,
val: 1,
};
}
// ... so it's easy to retrieve the item using the same key
allContinents[item.continent].val++;
console.log(allContinents[item.continent].val);
});
});