jeudi 7 mars 2019

get the object which only contains multiple selected values REACT

I have an array where I keep Id's of objects. I loop through all objects to find the ones containing ids from an array. If I select multiple checkboxes I get every object containing any id from array. But the goal is to get only those objects which contains all of the selected ones.

my code:

const checkbox = () => {
                let base = [];
                for(let i = 0; i < this.state.filterSelected.length; i++){
                    let foo =  data.filter(article => article[property] ? article[property].includes(this.state.filterSelected[i]) : null );
                    base.push(foo)
                }

                let uniqueObj = [...new Map(base.flat().map(o => [o.id, o])).values()]

                this.setState({print: uniqueObj})

            }

How can I get only those with all selected values?




Aucun commentaire:

Enregistrer un commentaire