在离子 3 中用两个值过滤数组



>我有更高的价格值和更低的价格值。我有一个数组..所以现在我需要过滤高价和低价之间的数组

High price = 90;
low price = 20;
actual array = [
{ price: "10" },
{ price: "30" },
{ price: "40" },
{ price: "70" },
{ price: "90" },
{ price: "100" }
];

所以现在在过滤器之后,我只需要在值之间。

array = [
{ price: "30" },
{ price: "40" },
{ price: "70" },
{ price: "90" }
];

您可以使用filter方法:

let array = [
{ price: "10" },
{ price: "30" },
{ price: "40" },
{ price: "70" },
{ price: "90" },
{ price: "100" }
];
let highPrice = 90;
let lowPrice = 20;
const result = array.filter(s => s.price >= lowPrice && s.price <= highPrice)
console.log(result)

最新更新