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

want to filter an array

I want to get an array with filtered values.
My arrays are like,

let arr=[{name:'trt,tet', id:5},{name:td, id:25},{name:fxg, id:1},{name:fs, id:4},{name:ste, id:41}]

&

let arr1 =[{data:fxg, addr:po 87987},{data:tert, addr:po8798fvd7},{data:trt, addr:po 887},{data:trhd, addr:po 8798787}]

my resultant array that I want is,

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

let rslt =[data:tert, addr:po8798fvd7},{data:trhd, addr:po 8798787}]

that is in arr the object ‘name’ which is also in arr1 with name ‘data’ I don’t need that array. nd some of which contain more than one name. I want to filter it.

>Solution :

try this

let arr=[{name:'trt,tet', id:5},{name:'td', id:25},{name:'fxg', id:1},{name:'fs', id:4},{name:'ste', id:41}]
let arr1 =[{data:'fxg', addr:'po 87987'},{data:'tert', addr:'po8798fvd7'},{data:'trt', addr:'po 887'},{data:'trhd', addr:'po 8798787'}]


const names = arr.flatMap(a => a.name.split(','))

const res = arr1.filter(a => !names.includes(a.data))

console.log(res)
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