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

211
Views
How to get particular keys from an object?

I have an object:

a = {
"1": "abc",
"2": "def",
"3": "ghi",
"4": "jkl"
}

and an array: b = ['abc','ghi'] I want to get keys from the objects which values are in an array and place them in another array, so expected output is: ['1', '3'].

I have no idea how to filter object properties. I tried mapping an array and get values but I get undefined.

    const result = b.map(v => a[v])
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You could use Object.keys(a).filter(...), and only return true if a[key] is in the b array.

about 4 years ago · Juan Pablo Isaza Report

0

Use filter() on the Object.keys():

const a = {"1": "abc", "2": "def", "3": "ghi", "4": "jkl"}; 
const b = ['abc','ghi']

const c = Object.keys(a).filter(k => b.includes(a[k]));
console.log(c);

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!