【问题标题】:filter the array with two value in ionic 3用 ionic 3 中的两个值过滤数组
【发布时间】:2020-02-05 07:44:11
【问题描述】:

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

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" }
    ];

【问题讨论】:

    标签: arrays sorting ionic-framework filter ionic3


    【解决方案1】:

    你可以使用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)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-02-01
      • 1970-01-01
      • 2018-07-05
      • 1970-01-01
      • 2018-04-19
      • 1970-01-01
      • 1970-01-01
      • 2016-06-11
      相关资源
      最近更新 更多