0
How to print array one by one in using button js
JavaScript
4 Antworten
+ 2
You can use a simple for loop.
Use the document.writeln to print it out. See the below working snippet.
array = ["example1", "example2", "example3"]; for (i = 0; i < array.length; i++) document.writeln((i+1) + ": " + array[i]);
+ 1
You may use.
For loop
For..in loop
For..of loop
+ 1
Thanks
0
There are several ways. Seeing as for loops and for of loops have been mentioned, I'll add forEach to the list.
For the outputting itself, you can use console.log, document.write or another couple of methods, depending on your needs.
Here's forEach:
["a", "b"].forEach(item => console.log(item))