Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [
- {
- "company": "Google",
- "location": "USA",
- "email": null
- },
- {
- "company": "Microsoft",
- "location": "USA",
- "email": "mail@mail.com"
- },
- {
- "company": "Google",
- "location": "NLD",
- "email": "mail@mail.com"
- }
- ]
- [x] Google (2)
- [ ] Microsoft (1)
- // other function call
- [ ] mail@mail.com (2)
- 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");
Add Comment
Please, Sign In to add comment