Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8510661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:45:59+00:00 2026-06-11T03:45:59+00:00

I have to access property on object: var jsonobj= { first: { second: 120

  • 0

I have to access property on object:

var jsonobj= {
    "first": {
        "second": 120
    }
}

How to check if second is available or not? jsonobj.hasOwnProperty() returns false if we check here.

If I want to change the value of second from 120 to 100, how can I achieve it?
Can I get a generalized solution, so that it works for any number of hierarchies?

Edit:
What if I don’t know the name of the property?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T03:46:00+00:00Added an answer on June 11, 2026 at 3:46 am

    If you want to check the existence of [the unique path to] a nested property [key], this function may help:

    function keyPathExists(obj,keypath){
      var keys = keypath.split('.'), key, trace = obj;
      while (key = keys.shift()){
        if (!trace[key]){
          return null
        };
        trace = trace[key];
      }
      return true;
    }
    
    //usages
    var abcd = {a:{b:{c:{d:1}}}};
    keyPathExists(abcd,'a.b.c.d'); //=> 1
    keyPathExists(abcd,'a.b.c.d.e'); //=> null
    if (keyPathExists(abcd,'a.b.c.d')){
     abcd.a.b.c.d = 2;
    }
    

    Please read @nnnnnns comment, especially the provided link within it carefully.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

D2.0 classes have a __monitor class property that gives access to the class object's
if you have an object and set a property for it, you can access
Possible Duplicate: Dynamic object property name I have an object like this var localAppConfig
I have a JS Object: var testObj = new Object(); that has a property
I have created one aspx Page from that i need to access the property
I have a Private property that I want to access in my MS Test
I have a @property listOfSites declared in a class. I am unable to access
I have access to a joomla edition but not the source, and I need
I'm trying to access a property from inside an object . When I access
I have a JS object property defined in an object literal: reqHeader: [{name:'Chris'},{age:'06'}] which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.