0

Transform the array based on the onChange min/max values.

arr = [
    {id:1, price:10},
    {id:2, price:5},
    {id:3, price:25}.....
    ]

on Change, I get two values:- minimum value and maximum value of price.

Suppose minimum value = 7 and maximum value = 20.

The new array should look like this

arr = [{id:1, price:10}]
developer
  • 301
  • 3
  • 14

2 Answers2

1

Maybe this code can help you

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)
Ali Torki
  • 1,929
  • 16
  • 26
1

You can use filter method to get the solution. Please check the below code.

const arr = [
  {id:1, price:10},
  {id:2, price:5},
  {id:3, price:25}
];
const minValue = 7;
const maxValue = 20;
const filterProduct = (arr, min, max) => arr.filter(item => item.price > minValue && item.price < maxValue);
console.log(filterProduct(arr, minValue, maxValue));