My goal is to calculate the total number of entries based on the color provided by the user. For instance, if the user enters 'red', the program should return 11. I attempted to achieve this but encountered an issue with the variable cnt not being defined after the loop.
let description=[
{color:'red',qty:6,remarks:'asdf'},
{color:'green',qty:5,remarks:'asdf'},
{color:'red',qty:5,remarks:'asdf'},
{color:'yellow',qty:5,remarks:'asdf'},
{color:'blue',qty:5,remarks:'asdf'},
{color:'white',qty:5,remarks:'asdf'}
];
{description.map((t,index) =>{
let cnt=0;
if(t.color=='red'){
cnt=cnt+parseInt(t.qty);
}
console.log(cnt);
}
)}
console.log(cnt);