JSFiddle - React, Tailwind, and code Playground
JavaScript
(function() {
"use strict"
let data = [
{
"company": "Google",
"location": "USA",
"email": null
},
{
"company": "Microsoft",
"location": "USA",
"email": "[email protected]"
},
{
"company": "Google",
"location": "NLD",
"email": "[email protected]"
}
]
function filterArr(data, key) {
data.forEach(element => {
let countedData = data.filter((el) => {
return el[key] == element[key]
}).length;
console.log(element[key] + ": " + countedData);
});
data = data.filter((item, index, self) => self.findIndex( t => t[key] === item[key] && item[key] != null) === index )
console.log(data);
return data;
}
filterArr(data, "company");
}());