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 8413133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:51:39+00:00 2026-06-10T00:51:39+00:00

I am writing a JavaScript utility which allows a user to detect if a

  • 0

I am writing a JavaScript utility which allows a user to detect if a particular object / function is available at runtime. Here is the source code, this works but it needs editing every time you want to test for another object:

<!DOCTYPE html>
<html>
    <head>
        <title>HTML5 Template</title>
        <meta http-equiv="content-type" content="text/html; charset=utf-8">
        <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
        <script type="text/javascript">
            $(document).ready(function() {
                $('#TestObject').click(function() {
                    alert(typeof(HTMLCollection));
                });
            });
        </script>
    </head>
    <body>
        <input id="ObjectType" type="text" />
        <input id="TestObject" type="button" value="Test" />
    </body>
</html>

When the button is clicked, it displays an alert indicating “object” or “function” if the item exists, and “undefined” if it does not.

What I want is to have a textbox <input id="ObjectType" type="text" /> where I can type in the object to test, and then click the button to test it, which will eliminate the need to keep editing the document. Is this possible? Is there anything similar to reflection that I can use?

  • 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-10T00:51:41+00:00Added an answer on June 10, 2026 at 12:51 am

    This is possible due to JavaScript object properties actually being associative key-value pairs, meaning that obj.property is equivalent to obj['property'].

    Applying this to your problem, the following code would work:

    alert(typeof(window[$('#ObjectType').val()]));
    

    This works because all “global” variables, are actually properties of the window object.

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

Sidebar

Related Questions

I'm writing javascript code for a web emulator containing function keys. The user is
Often during writing JavaScript, we have to write configuration object. For example Ext.define('User', {
i am writing javascript code on nodepad++,i am at beginner level and write just
I am writing a JavaScript function to highlight the row and column of a
I'm writing some Javascript code that generates an XML document in the client (via
I'm writing a Javascript function that would manipulate an array written on-the-fly and sent
I'm writing some Javascript code and I'm trying to change the current page as
I'm writing a utility that takes in a .resx file and creates a javascript
While writing JavaScript code, I Separate each code block with <script> tags <script type=text/javascript>
I'm writing a little JavaScript tool for myself that I plan on making available

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.