From 040efd4380b1271d656735399f6ad8c592cc0667 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=8A=80=E6=A1=91?= Date: Mon, 14 Sep 2020 15:37:40 +0800 Subject: [PATCH] Update arrayToHtmlList Co-authored-by: Angelos Chalaris --- snippets/arrayToHtmlList.md | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/snippets/arrayToHtmlList.md b/snippets/arrayToHtmlList.md index 1122b9bc0..d62d28f40 100644 --- a/snippets/arrayToHtmlList.md +++ b/snippets/arrayToHtmlList.md @@ -5,16 +5,15 @@ tags: browser,array,intermediate Converts the given array elements into `
  • ` tags and appends them to the list of the given id. -Use `Array.prototype.map()`, `document.querySelector()`, and an anonymous inner closure to create a list of html tags. +Use `Array.prototype.map()` and `document.querySelector()` to create a list of html tags. ```js -const arrayToHtmlList = (arr, listID) => - (el => ( - (el = document.querySelector('#' + listID)), - (el.innerHTML += arr.map(item => `
  • ${item}
  • `).join('')) - ))(); +const arrayToHtmlList = (arr, listID) => + document.querySelector(`#${listID}`).innerHTML += arr + .map(item => `
  • ${item}
  • `) + .join(''); ``` ```js arrayToHtmlList(['item 1', 'item 2'], 'myListID'); -``` \ No newline at end of file +```