题解 | #数组过滤#
数组过滤
https://www.nowcoder.com/practice/46d607f9bf64458daa8798339a7336d0
select.onchange = function() { ul.innerHTML = ''; switch(this.value) { case '1': var newArr = cups.filter((item) => { return item.sales<100 }) break; case '2': var newArr = cups.filter((item) => { return item.sales<=500 && item.sales>=100 }) break; case '3': var newArr = cups.filter((item) => { return item.sales>500 }) break; } initList(newArr) } function initList(arr) { arr.forEach(item => { let Li = document.createElement('li'); Li.innerHTML = item.name; ul.appendChild(Li); }) }