Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Filter 2 arrays

I have an array

let idarray = [55, 25, 24] 

and another array

let details = [
    {id:55, name:"GHN"},
    {id:46, name:"GTN"},
    {id:78, name:"AHN"},
]

I want to filter the object which has id in details aray equal to idarray.How to filter

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

let idarray = [55, 25, 24] 

let details = [
    {id:55, name:"GHN"},
    {id:46, name:"GTN"},
    {id:78, name:"AHN"},
]

const result = details.filter(item => {
    return idarray.includes(item.id)
})

as the comments suggested includes and filters should do it

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading