Tell us what’s happening:
I want to map an array that contains series of objects. Each object contains a ‘keyTrigger’ property. Values of this property are: ‘Q’, ‘X’ and ‘C’.
I am trying to map this property and to have my React component render it to the screen as buttons (button ‘Q’, ‘X’, etc.)
I receive an error in the console: ‘Uncaught TypeError: Cannot read property ‘keyTrigger’ of undefined’
Why is this property ‘undefined’. What corrections do I need to have this work?
Many thanks.
Your code so far
const beats = [
{
keyCode: 81,
keyTrigger: "Q",
id: "Heater-1",
url: "'https://s3.amazonaws.com/freecodecamp/drums/Heater-1.mp3'"
},
{
keyCode: 88,
keyTrigger: "X",
id: "Kick",
url: "https://s3.amazonaws.com/freecodecamp/drums/RP4_KICK_1.mp3"
},
{
keyCode: 67,
keyTrigger: "C",
id: "Closed-HH",
url: "https://s3.amazonaws.com/freecodecamp/drums/Cev_H2.mp3"
}
];
const key=beats.map((index, item)=>{
return(
beats[index].keyTrigger
);
});
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36
Challenge: Build a Drum Machine
Link to the challenge: