diff --git a/snippets/arrayToHtmlList.md b/snippets/arrayToHtmlList.md index 443f9c38b..6a55e19e0 100644 --- a/snippets/arrayToHtmlList.md +++ b/snippets/arrayToHtmlList.md @@ -2,11 +2,12 @@ Converts the given array elements into `
  • ` tags and appends them to the list of the given id. -Use `Array.map()` and `document.querySelector()` to create a list of html tags. +Use `Array.map()`, `document.querySelector()`, and an anonymous inner closure to create a list of html tags. ```js -const arrayToHtmlList = (arr, listID) => - arr.map(item => (document.querySelector('#' + listID).innerHTML += `
  • ${item}
  • `)); + const arrayToHtmlList = (arr, listID) => + (el => (el = document.querySelector('#' + listID), + el.innerHTML += arr.map(item => `
  • ${item}
  • `).join('')))() ``` ```js