// Complete the below questions using this array:
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"]
},
];
//Create an array using forEach that has all the usernames with a "!" to each of the usernames
const exclamArray = [];
const newArray = array.forEach((username) => {
exclamArray.push(array.username + '!');
})
console.log('forEach', exclamArray);
when i executed the code above, it gave me
forEach (4) ["undefined!", "undefined!", "undefined!", "undefined!"]
how can i select the object's value 'username'? have i done anything wrong on that code?
username, notarray.username. Or rather,(player) => { … player.username … }. And don't useforEach, butmap.