M
M
mr jeery2018-02-27 21:49:07
JavaScript
mr jeery, 2018-02-27 21:49:07

How to filter an array by another array?

I'm trying to create a filtering of an array of objects by the params array property, which contains string values.
includes takes the first string value, but how to pass an array?

List =  [
  {
    "id":12,
    "name": "Фламинго",
    "price": 1200,
    "view":[""],
    "params":["птица","окно"]
    },
    {
    "id":13,
    "name": "Семейная",
    "price": 1800,
    "view":[""],
    "params":["камин","качель","окно"]
    },
...
]

const mapStateToProps = state => (
    {
        list:state.list.filter(item => item.params.some(i=> i.includes(["качель","окно"]) )  ),
       
    }
);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2018-02-27
@jeerjmin

i.includes(["качель","окно"])

It should be the other way around, checking that the array contains a string and not a string array:
[ 'качель', 'окно' ].includes(i)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question