How to convert elements of an array into <li> tags?
const arrayToHtmlList = (array, listClass) =>
(el => (
(el = document.querySelector('.' + listClass)),
(el.innerHTML += array.map(item => `<li>${item}</li>`).join(''))
))()
arrayToHtmlList(['hello', 'world', '42'], 'classOfTheList')
September 29th, 2019
This snippet converts all elements of an array to a list of <li>
tags and appends them to the list of the given class.