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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:23:52+00:00 2026-05-28T03:23:52+00:00

I got another question regarding jQuery’s architecture. $(‘div’) constructs a new jQuery object: $(‘div’)

  • 0

I got another question regarding jQuery’s architecture. $('div') constructs a new jQuery object:

$('div') instanceof jQuery; // true

I’d like to know why it is possible to query it like an array, allthough it isn’t an array?

$('div')[0]; // returns the first div in the document as a DOM node.
$.isArray($('div')); // false

I just love this syntax, it looks so clean! I also noticed this returns the DOM nodes as an array:

console.log($('div'));

Can somebody explain me how to implement this behaviour to my own objects?


My own approach was to make an array with some methods like this:

var a = ['a', 'b', 'c'];
a.method = function(){ return 'test'; };
a; // ['a', 'b', 'c']
a[0]; // 'a'
a.method(); // 'test'

However this doesn’t seem to be the way jQuery does it as this is actually an array:

$.isArray(a); // true

I’d like to know how jQuery does this to learn and to see if it’s a better solution than mine.

  • 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-05-28T03:23:53+00:00Added an answer on May 28, 2026 at 3:23 am

    A jQuery object is what we call a Array-like object. That means, it indeed is a “true” object (infact, all “arrays” are objects in ECMAscript), but it owns certain properties which make it look like a “true” array. Those properties are

    • it as a .length property
    • it owns the .splice() method

    those two facts are enough that most js engines consoles will interpretate that object as array.

    Example:

    var myObject = { },
        push = Array.prototype.push;
    
    myObject.aNiceFunction = function() {
        console.log(this);
    };
    
    push.call( myObject, document.getElementById('foo') );
    push.call( myObject, document.getElementById('bar') );
    
    myObject.splice = Array.prototype.splice;
    

    If we now log our object

    console.log( myObject );
    

    we get the typical jQuery’ish result

    [div#foo, div#bar]
    

    See that in action

    but we are still able to call our method .aNiceFunction() on that object. By pushing new elements with the Array.prototype.push() method onto our object, ECMAscript will automatically index those elements for us. That was short description what happens under the jQuery hood.

    One more word about “Arrays” in ECMAscript. There are no real arrays in this language (if we forget about typed arrays for a second). There is only Object. If we have an object that inherits from Array.prototype we would almost call it an array. Everything we would have left to do is, set the .length property to 0.

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

Sidebar

Related Questions

I've got another question regarding to basic Android programming: How can I access the
i got a question when create a javascript object, when one function invoking another
I was just reading another question about jQuery's synchronous ajax call, and I got
Howdy, I've got another question regarding phone 7... I want to generate a couple
I got into another philosophical question regarding Java. It's about the following scenario: You
I've got a question regarding jQuery keypress events. I've got the following (working) code:
In another question I posted yesterday, I got very good advice on how a
I've got the following code from another question on SO to track the changing
Time for another silly question :) I got some tables in a xhtml-document with
(I asked this question in another way , and got some interesting responses but

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.