Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

232
Views
If an object value exists in an array of objects then return entire object

I have one array and one object:

const currentData = [{first: 'Breanna', last: 'Bazadoo', uid: '-Lz8YxHiwp8QZW3TqAFn'},
{first: 'Foo', last: 'Bazado', uid: '-Lz8YxHqQXWoaGOFRLrO'},
{first: 'Foo2', last: 'Bazado', uid: '-Lz8YxHsMItaaTVNyQRE'},
{first: 'Foo3', last: 'Bazado', uid: '-Lz8YxHy0S-QkDaE1PkX'}
];

const ministryMembers = { -MmFNu4jQ8A4_Aig0vdn: "-MmFNu4jQ8A4_Aig0vdn",
-Mxg8xKwZleW4J8yfzna: "-Lz8YxHqQXWoaGOFRLrO",
-Mxg9AxhUR6ZArBATw1M: "-Lz8YxHsMItaaTVNyQRE",
-Mxg9ECyBsj01zMqPE8s: "-MmFNgjyopU3E8z5g-zU",
-Mxg9GvmPFabK_185IOr: "-Lz8YxLVi_uZp_RkcRIH",
-Mxg9JbJ2sxgWLxk1tfx: "-MuEgimJOIbPw3GyKBJ3",
-Mxg9MZTKzlUD0lg07C0: "-Lz8YxHy0S-QkDaE1PkX",
-Mxg9Pnfmv7P3BQvINQV: "-Lz8YxJ-_wuk8bmEyvGT",
-Mxg9SB2vlOopJYtmG-Z: "-Lz8YxKj5WXY1oNwylQ4",
-Mxg9VrZFDNawvcWIgul: "-Lz8YxN87U1YM6_fKgq1" }

if currentData's uid is found in allMembers value in example currentData uid == allMembers value, I want to return the entire object from currentData and build the array again. There will be a lot more in currentData this is just an example.

I have done this:

const filteredData = Object.keys(ministryMembers).filter( m => currentData.find( cd => cd.uid == ministryMembers[m] ) );
console.log(filteredData);

It returns only the key. How can I get it to return the whole object? My other option was map the data and then return the whole object that way but I thought that there might be a more efficent way of doing it. Any thoughts?

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Does it work?

var valueList = Object.values(ministryMembers);
var filteredData = currentData.filter(e => valueList.includes(e.uid));

JsFiddle: https://jsfiddle.net/03bpak9m/2/

about 4 years ago · Juan Pablo Isaza Report

0

Try this -

currentData.filter(e => typeof allMembers[e.uid] !== 'undefined')

or

currentData.filter(e => allMembers.hasOwnProperty(e.uid))
about 4 years ago · Juan Pablo Isaza Report

0

If there is large data then you can process it in chunks.

var filteredArray = [];
function processData(data, allMembers) {
  // process data in chunks -> 100 at a time
  let chunks = data.splice(0, 100);
  chunks.forEach((element) => {
    if (Object.keys(allMembers).find((e) => allMembers[e] === element.uid)) {
      filteredArray.push(element);
    }
  });
  if (data.length > 0) {
    setTimeout(() => {
      processData(data,allMembers);
    }, 0);
  } else {
    // processing complete
    console.log(filteredArray);
  }
}

var currentData = [{first: 'Breanna', last: 'Bazadoo', uid: '-Lz8YxHiwp8QZW3TqAFn'},
{first: 'Foo', last: 'Bazado', uid: '-Lz8YxHqQXWoaGOFRLrO'},
{first: 'Foo2', last: 'Bazado', uid: '-Lz8YxHsMItaaTVNyQRE'},
{first: 'Foo3', last: 'Bazado', uid: '-Lz8YxHy0S-QkDaE1PkX'}
];

var ministryMembers = { "-MmFNu4jQ8A4_Aig0vdn": "-MmFNu4jQ8A4_Aig0vdn",
"-Lz8YxHiwp8QZW3TqAFn": "-Lz8YxHqQXWoaGOFRLrO",
"-Lz8YxHqQXWoaGOFRLrO": "-Lz8YxHsMItaaTVNyQRE",
"-Mxg9ECyBsj01zMqPE8s": "-MmFNgjyopU3E8z5g-zU",
"-Mxg9GvmPFabK_185IOr": "-Lz8YxLVi_uZp_RkcRIH",
"-Mxg9JbJ2sxgWLxk1tfx": "-MuEgimJOIbPw3GyKBJ3",
"-Mxg9MZTKzlUD0lg07C0": "-Lz8YxHy0S-QkDaE1PkX",
"-Mxg9Pnfmv7P3BQvINQV": "-Lz8YxJ-_wuk8bmEyvGT",
"-Mxg9SB2vlOopJYtmG-Z": "-Lz8YxKj5WXY1oNwylQ4",
"-Mxg9VrZFDNawvcWIgul": "-Lz8YxN87U1YM6_fKgq1" };

processData(currentData,ministryMembers);

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!