In my JavaScript code, I have an array called Projects and another one called Teams.
const Projects = [{fkTeamId: 'a'}, {fkTeamId: '8'}, {fkTeamId: 'c'}, {fkTeamId: 'a'}];
const Teams = [{TeamId: 'a'}, {TeamId: 'c'}, {TeamId: '8'}];
const output = Projects.filter(item1 => Teams.some(item2 => item2.TeamId === item1.fkTeamId))
console.log(output)
The goal is to determine the number of projects associated with each team. For example, if "TeamID: a" has 2 projects, I want to know that specifically. My initial idea was to store this information in an array and then use the .length method, but I am uncertain on how to proceed.
Currently, the code generates the following output:
Array [Object { fkTeamId: "a" }, Object { fkTeamId: "8" }, Object { fkTeamId: "c" }, Object { fkTeamId: "a" }]
How can I utilize the .length property to determine the project count for each Team ID?
In simpler terms, I am attempting to achieve something like this:
const count = [[{fkTeamId: "a"},{fkTeamId: "a"}], [{fkTeamId: "8"}], [{fkTeamId: "c"}]];
console.log(count.forEach(Team => Team.length))
The objective of the aforementioned code snippet is to produce an array or similar structure containing:
count = [2, 1, 1]