根据 onChange 最小/最大值转换数组。
arr = [
{id:1, price:10},
{id:2, price:5},
{id:3, price:25}.....
]
在更改时,我得到两个值:- 价格的最小值和最大值。
假设最小值 = 7,最大值 = 20。
新数组应如下所示
arr = [{id:1, price:10}]
最佳答案
也许这段代码可以帮助你
function findItemsByMinAndMax (array, min, max) {
return array.filter(item => {
return item.price >= min && item.price <= max
})
}
const arr = [
{ id: 1, price: 10 },
{ id: 2, price: 5 },
{ id: 3, price: 25 },
];
cont foundItems = findItemsByMinAndMax(arr, 7, 20)
console.log(foundItems)
关于javascript - 基于最小值和最大值的新数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60440962/