I'm trying to use map method use instead of for loop using React Typescript for below code but not working
Actual Code using for loop :
renderFunction(perkProgressData) {
let tiers = [];
let currentData = { item: {} }
const data = perkProgressData.perkProgressData
if (data && data.program && data.program.tiers) {
tiers = data.program.tiers
**for (let i = 0; i < tiers.length; i++) {**
if (tiers[i].tierPerks[0].perkStatus === "UNCLAIMED" ||
data.currentTierId === tiers[i].tierId) {
currentData = { item: tiers[i] }
break;
}
}
}
tried using .map():(Not Working )
renderFunction(perkProgressData) {
let tiers = [];
let currentData = { item: {} }
const data = perkProgressData.perkProgressData
if (data && data.program && data.program.tiers) {
tiers = data.program.tiers
tiers.map((val) => {
if (val.tierPerks && val.tierPerks[0].perkStatus === "UNCLAIMED" ||
data.currentTierId === val.tierId) {
currentData = { item: val }
}
});
}
}
mapin that code. You don't need the new array it creates.forloop, you could use aforEach, but notmapfor sureforEachin that casesomething. But really, what they're doing is finding something in the array, sofind. But it's troubling, I've seen a lot of this "mapas a general way to loop through arrays" misunderstanding the last 18-24 months. Someone must be mis-teaching this.