Merge pull request #661 from xiangwenhu/master

update arrayToHtmlList to more high efficiency
This commit is contained in:
Stefan Feješ
2018-05-07 10:32:56 +02:00
committed by GitHub

View File

@ -2,11 +2,12 @@
Converts the given array elements into `<li>` 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 += `<li>${item}</li>`));
const arrayToHtmlList = (arr, listID) =>
(el => (el = document.querySelector('#' + listID),
el.innerHTML += arr.map(item => `<li>${item}</li>`).join('')))()
```
```js