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

166
Views
How to write a function which represents an object lookup path

Write a function that takes a object and a string, which represents an object lookup path, for example "something1.something2". The function should return the value on the specific path. Example:

const lookup = (obj, path) => {....}
const obj = { something1: { something2: "Mouse", something3: 'Cat' } };
const path = 'something1.something2'
console.log(lookup(obj, path));

Result: 'Mouse'

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

0

You can use split and then reference the property dynamically using square brackets

const lookup = (obj, path) => {
    const paths = path.split('.');
    return obj[paths[0]][paths[1]];
}

const obj = { something1: { something2: "Mouse", something3: 'Cat' } };
const path = 'something1.something2'

console.log(lookup(obj, path));

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!