const xx = [" 4", "9", "16"," 4", "9", "16"," 4", "9", "16"]
<ul> {(<li> {[...new Set(xx)]} </li>)} </ul>
const xx = ["4", "9", "4", "9", "4", "9", "16&;]
- {(
- {…new Set(xx)]} div)}
这里可以正常工作
const xx = [" 4", "9", "16"," 4", "9", "16"," 4", "9", "16"];
const set = [...new Set(xx)];
let html = '';
set.forEach(el => {
html += `<li>${el}</li>`;
});
document.querySelector("#list").insertAdjacentHTML('afterbegin', html);
<ul id="list"></ul>
您也可以对数组方法
执行相同的操作
const xx = [" 4", "9", "16"," 4", "9", "16"," 4", "9", "16"];
const html = [...new Set(xx)].map(el => `<li>${el}</li>`).join('');
document.querySelector("#list").insertAdjacentHTML('afterbegin', html);
<ul id="list"></ul>