how to print a list in javascript 1

how to print a list in javascript

var array = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('');
for (var i = 0; i < array.length; i++) {
  var str = '';
  for (var j = 0; j <= i; j++) {
    if (array[j] == 'E') str += '3';
    else str += array[j];
  }
  document.querySelector('span').innerHTML = document.querySelector('span').innerHTML + str + '
'; }

Here is what the above code is Doing:
1. It creates an array of the alphabet.
2. It loops through the array.
3. It creates a string.
4. It loops through the array again.
5. It checks if the current letter is ‘E’.
6. If it is, it adds ‘3’ to the string.
7. If it isn’t, it adds the current letter to the string.
8. It adds the string to the HTML.
9. It repeats steps 2-8 until it has looped through the array.

Similar Posts