An array is given below. I would like to get the username for every single member of this array whose team is red!
const array = [
{
username: "john",
team: "red",
score: 5,
items: ["ball", "book", "pen"]
},
{
username: "becky",
team: "blue",
score: 10,
items: ["tape", "backpack", "pen"]
},
{
username: "susy",
team: "red",
score: 55,
items: ["ball", "eraser", "pen"]
},
{
username: "tyson",
team: "green",
score: 1,
items: ["book", "pen"]
},
];
I've tried this code:
const colorTeam = array.filter(teams=>teams.team === 'red');
console.log('teamColor:', username);
It didn't work!
console.log('teamColor:', username);, where isusernamesupposed to be coming from? And why is that line not usingcolorTeamfrom the previous line?