You need to make result
an array and push onto it, not reassign it.
function showData() {
var secondP = document.getElementById('secondP');
var num = 2
console.log("this is" + num)
let result = [];
for (var i = 1; i <= 5; i++) {
result.push(i * num);
}
secondP.innerHTML = ('Its Standerd Pack is: ' + num + " we have to choose " + result.join(", "));
}
showData();
<p id="secondP"></p>
Sorry if I got it wrong but if you were having trouble to show the items in an array separated by a comma (or anything else),
the simplest solution I have is arr.join(“, “)
or a neat code
const arr = [1, 2, 3, `a`, `b`, `c`];
function showFullArrayList(arr) {
console.log(arr.join(`, `));
}
showFullArrayList(arr);
I am trying to show the whole array separated with a comma in the HTML body. So far, the whole ArrayList is the result of the multiplication of specific values, so if the value is 2, then ArrayList will be (2,4,6,8,10).
I have created the multiplication function using js and in console, I can see the ArrayList. But whenever I am trying to show this list in HTML using innerHTML, I only can see 10 (for multiplication of 2), but can not visualize the whole list.
function showData() {
var theSelect = demoForm.part;
var secondP = document.getElementById('secondP');
var num = theSelect[theSelect.selectedIndex].value
console.log("this is" + num)
for (var i = 1; i <= 5; i++) {
result = i * num;
console.log("List is" + result);
}
secondP.innerHTML = ('Its Standerd Pack is: ' + theSelect[theSelect.selectedIndex].value + " we have to choose" + result);
}
<p id="secondP"></p>
Current output is:
Its Standard Pack is: 2 we have to choose 10
Expected output:*
Its Standard Pack is: 2 we have to choose 2,4,8,10
Any suggestion on how to do that. Thank you very much