How to filter array when object key value is in array

前端 未结 6 823
迷失自我
迷失自我 2020-11-28 08:16

I have an array model as below:

records:[{
    \"empid\":1,
    \"fname\": \"X\",
    \"lname\": \"Y\"
},
{
    \"empid\":2,
    \"fname\": \"A\",
    \"lnam         


        
6条回答
  •  难免孤独
    2020-11-28 08:46

    In case you have key value pairs in your input array, I used:

    .filter(
              this.multi_items[0] != null && store.state.isSearchBox === false
                ? item =>
                    _.map(this.multi_items, "value").includes(item["wijknaam"])
                : item => item["wijknaam"].includes("")
            );
    

    where the input array is multi_items as: [{"text": "bla1", "value": "green"}, {"text": etc. etc.}]

    _.map is a lodash function.

提交回复
热议问题