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

  • Home
  • SEARCH
  • 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 7725725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T05:00:46+00:00 2026-06-01T05:00:46+00:00

Suppose I have a javascript object like this: window.config config.UI = { opacity: {

  • 0

Suppose I have a javascript object like this:

window.config
config.UI = {
        "opacity": {
            "_type": "float",
            "_tag": "input",
            "_value": "1",
            "_aka": "opacity",
            "_isShow":"1"
 }

How can I judge if the “opacity” object has a property named “_test”?
like

var c=config.ui.opacity;
for(var i in c)
{
   //c[i]=="_test"?
}

How do I find out if it’s assigned as well?

  • 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-01T05:00:47+00:00Added an answer on June 1, 2026 at 5:00 am

    There are at least three ways to do this; which one you use is largely up to you and sometimes even a matter of style, though there are some substantive differences:

    if..in

    You can use if..in:

    if ("_test" in config.UI.opacity)
    

    …because when used in a test (as opposed to the special for..in loop), in tests to see if the object or its prototype (or its prototype’s prototype, etc.) has a property by that name.

    hasOwnProperty

    If you want to exclude properties from prototypes (it doesn’t much matter in your example), you can use hasOwnProperty, which is a function all objects inherit from Object.prototype:

    if (config.UI.opacity.hasOwnProperty("_test"))
    

    Just retrieve it and check the result

    Finally, you can just retrieve the property (even if it doesn’t exist) and the decide what to do with the result by looking at the result; if you ask an object for the value of a property it doesn’t have, you’ll get back undefined:

    var c = config.UI.opacity._test;
    if (c) {
        // It's there and has a value other than undefined, "", 0, false, or null
    }
    

    or

    var c = config.UI.opacity._test;
    if (typeof c !== "undefined") {
        // It's there and has a value other than undefined
    }
    

    Being defensive

    If it’s possible that config.UI won’t have an opacity property at all, you can make all of those more defensive:

    // The if..in version:
    if (config.UI.opacity && "_test" in config.UI.opacity)
    
    // The hasOwnProperty version
    if (config.UI.opacity && config.UI.opacity.hasOwnProperty("_test"))
    
    // The "just get it and then deal with the result" version:
    var c = config.UI.opacity && config.UI.opacity._test;
    if (c) { // Or if (typeof c !== "undefined") {
    

    That last one works because the && operator is particularly powerful in JavaScript compared with some other languages; it’s the corollary of the curiously-powerful || operator.

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

Sidebar

Related Questions

Suppose I have JavaScript code like myClass = function(){ function doSomething(){ alert(this); // this1
Possible Duplicate: Pick random property from a Javascript object suppose I have a javascript
Quick rookie question please. Suppose I have a javsacript object like so: var meh=[[cars,27],
Let's suppose I want to create a javascript class/object/function which have a method that
Suppose I have an object foo in my JavaScript code. foo is a complex
Suppose I have a stringbuilder in C# that does this: StringBuilder sb = new
Suppose I have a class module clsMyClass with an object as a member variable.
Suppose I have javascript within ASP.NET UserControl: function setValue(DataItem) { var selectedDate = DataItem.getMember('DomainNameKey').get_object();
Suppose I create a custom object/javascript class (airquotes) as follows: // Constructor function CustomObject(stringParam)
I have a page that looks like this: <div class=post> <h1>Foo Bar</h1> </div> I

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.