Answer the question
In order to leave comments, you need to log in
How to filter by one or more parameters?
I have an example array of objects:
data = [
{ bg: 'black', color: 'green' },
{ bg: 'black', color: 'green' },
{ bg: 'black', color: 'red' },
{ bg: 'black', color: 'red' },
{ bg: 'white', color: 'green' },
{ bg: 'white', color: 'green' },
{ bg: 'white', color: 'red' },
{ bg: 'white', color: 'red' }
]
[
{ bg: 'black', color: 'green' },
{ bg: 'black', color: 'green' },
{ bg: 'black', color: 'red' },
{ bg: 'black', color: 'red' }
]
[
{ bg: 'black', color: 'red' },
{ bg: 'black', color: 'red' }
]
filters = {
bg: 'white', // or 'none', or 'black'
color: 'none', // or 'red, or 'green'
}
Answer the question
In order to leave comments, you need to log in
const filterColor = chosedColor => currColor => chosedColor === 'none' ? true : currColor === chosedColor
arr.filter(filterColor(inputValue1)).filter(filterColor(inputValue2))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question