Personally I would use map
and store each variable on an object, like so:
const sums = { [key: string]: <insert type of each Table2 item> }
if (this.storedData?.Table2?.length)
{
this.storedData.Table2.map((tableItem, index) =>
sums[`sum${index || ''}`] = tableItem
)
if(sums.sum.DataId = '4')
{
//do logic here
}
...
This will build a dynamic dictionary of objects for you, but I'm not sure what you want wanting to do with the if
statement and the do logic here
parts of the code. Could you elaborate your requirements a bit there please?