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

119
Views
Check nested js object properties in js

I'd like to check the existence of a nested js object property, any way to simplify this code in one line?

if(json_root.hasOwnProperty(p1)){
    if(json_root.p1.hasOwnProperty(p2)){
        if(json_root.p1.p2.hasOwnProperty(p3)){
            /**Do your things with json_root.p1.p2.p3*/
        }
    }
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can just define a if statement like this

if(json_root.p1 && json_root.p1.p2 && json_root.p1.p2.p3){
    // Here add your code
}

The block code of the if statement will be executed only when all three condition are valid.

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!