I wanted to fetch the Button Click value and pass it to the map method so only that part of the array is executed, I'm trying the pass the value using back tics. can you guys help me where I'm getting this wrong?
const productData = {
ProductA: {
CountryA: [{
id: 'Product A',
avilabllity: 'Amazon',
shopUrl: 'https://'
}
],
CountryB: [{
id: 'Product B',
avilabllity: 'Amazon',
shopUrl: 'https://'
}
],
},
}
$( ".myButton" ).click(function() {
var buttonId = this.id;
//How To Dynmically Get "ProductA" data from this.id on button click so when i Click on ProdctB, this.id will change.
const mytData = productData.ProductA.CountryA.map(myId => myId.id);
// const whatIWant = productData.`${buttonId}`.CountryA.map(myId => myId.id);
//console.log(whatIWant)
console.log(mytData);
console.log(buttonId)
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<Button class="myButton" id="productA" >Product A</Button>
<Button class="myButton" id="productB" >Product B</Button>
<Button class="myButton" id="productC" >Product C</Button>