Java Script is still quite new to me and I could really use some assistance with a specific issue in the code snippet below. I am using an IF Statement to validate an incoming SNS Message. If it matches, I want to display the message values.
else if (obj.intent === "list" && obj.message === 'success'){
var innerHTMLval = '<table class="test"><tr><td class="test-loc"><img src="favicon.png" width="10%"></td><td class="test-loc"> View</td></tr>'
+ ' <tr><td class="forecast">'+ obj.artikel0+ '</td><td class="forecast">' + obj.stueckzahl0 + '</td> </tr>'
+ ' <tr><td class="forecast">'+ obj.artikel1+ '</td><td class="forecast">' + obj.stueckzahl1 + '</td> </tr>'
+ ' <tr><td class="forecast">'+ obj.artikel2+ '</td><td class="forecast">' + obj.stueckzahl2 + '</td> </tr>'
+ '</table>'
document.getElementById('display').innerHTML = innerHTMLval;
}
While everything is working smoothly, I am now curious if there is a way for me to utilize a for loop to dynamically add lines based on the payload count.
This is how my payload looks:
{
"intent": "list",
"message": "success",
"artikel0": "A",
"stueckzahl0": 10,
"artikel1": "B",
"stueckzahl1": 10,
"artikel2": "A",
"stueckzahl2": 10,
"artikel3": "C",
"stueckzahl3": 10,
}
Can anyone advise me on how to add these lines using a For loop that adjusts according to the number of lines in the payload?
Thank you so much