How would I further access the "name" and "description" from this object array? For example my goal is to render two buttons that say Term 1 and Term 2? I will have 3 slides each with different terms/definitions. So i thought about making a component, where I can pass down an index via props that refers to the set of terms to render. So each slide will show a different set of term names and definitions.
const TermData = [
{
index: 1,
slideTitle: "Key Terms (1 of 3)",
terms: [
{
name: "Term 1",
definition: "Definition 1",
},
{
name: "Term 2 ",
definition: " definition 2",
},
],
},
{
index: 2,
slideTitle: "Key Terms (2 of 3)",
terms: [
{
name: "Term 1",
definition: "Definition 1",
},
{
name: "Term 2 ",
definition: " definition 2",
},
],
},
];
//MAP THROUGH THE DATA - RENDER THE BUTTONS WITH TERM1 and TERM2 TITLE//
const termSet = TermData.map((set, index) => {
return (
<>
<button className="terms-button" key={index} onClick={() => handleClick(index)}>
{set.terms[0].name}
</button>
</>
);
});
return (
<Fragment>
<div>
{termSet}
</div>
</Fragment>
);