参考答案
select.onchange = function () {
let newArr = arrFilter(select.value);
Render(newArr)
}
function arrFilter(index) {
let newArr = []
if (index === '1') {
newArr = cups.filter((c, i, arr) => {
return c.sales < 100
})
} else if (index === '2') {
newArr = cups.filter((c, i, arr) => {
return (c.sales >= 100 && c.sales <= 500)
})
} else {
newArr = cups.filter((c, i, arr) => {
return (c.sales > 500)
})
}
return newArr;
}
function Render(renderArr) {
ul.innerHTML = '';
renderArr.forEach(element => {
ul.innerHTML += `<li>${element.name}</li>`
})
}