V
V
Vladislav2017-05-16 12:14:09
JavaScript
Vladislav, 2017-05-16 12:14:09

Finding a value in an array of objects using underscore?

Hello. Something I can not understand how to look for values ​​inside an array with objects, if the object also contains an array.
The structure is like this:

[{
        id: 0,
        regions: [
            "region1",
            "region2"
        ]
    },
    {
        id: 1,
        regions: [
            "region3",
            "region2"
        ],
        {
            id: 2,
            regions: [
                "region1"
            ]
        }
    }
]

I need to get matches with my key (for example, "region1"), but I don't understand. I tried to use each, and find \ where inside it, but it doesn't work.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Kitmanov, 2017-05-16
@vlad00777

arr.filter((elem) => elem.regions.includes('region1'))

Rewrite on underscore or can you handle it yourself?)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question