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

291
Views
how to access a property of an object, if the property name is not fully known?

How to access a property of a javascript object if property name is not fully known? Need to access value by knowing that "totalCount" will be part of property name. Sample :

[
  {"totalCount_12":100},
  {"totalCount_13":100},
  {"totalCount_2":100}
]
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

I hope this piece of code will help you

a = {"totalCount_12":100}
a[Object.keys(a).filter(i=>i.includes("totalCount"))[0]]
about 4 years ago · Juan Pablo Isaza Report

0

You can achieve this by creating a special function that finds 'totalCount_'+n (n is a given number)

const list = [
  {"totalCount_12":75},
  {"totalCount_13":100},
  {"totalCount_2":150},
  {"totalCount_14":17}
]

const findByPartlyKnownName = (n) => list.find(el => Object.keys(el)[0].includes(`totalCount_${n}`))

console.log(findByPartlyKnownName(12))
console.log(findByPartlyKnownName(14))
console.log(findByPartlyKnownName(2))
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!