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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:40:11+00:00 2026-05-24T02:40:11+00:00

var test = $(); test.push( $(‘div’)[0] ); This works. Any idea why? Since push

  • 0
var test = $();
test.push( $('div')[0] );

This works. Any idea why?
Since push is a array method, I don’t understand why this works in this case, any idea?

Is there a practical use for it since you can use .add() ?

  • 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-24T02:40:11+00:00Added an answer on May 24, 2026 at 2:40 am

    They borrow .push() from Array.prototype.

    https://github.com/jquery/jquery/blob/1.6.2/src/core.js#L70

    and

    https://github.com/jquery/jquery/blob/1.6.2/src/core.js#L296

    Example: http://jsfiddle.net/HgS2R/1/

    var MyObj = function(){};
    MyObj.prototype.push = Array.prototype.push;
    
    var inst = new MyObj;
    
    inst.push( "test" );
    
    document.write( inst[ 0 ] + '<br>' + inst.length );  // test, 1
    

    Just be aware that instances of your custom constructor won’t behave identically to an actual Array.


    EDIT:

    With respect to the edit in your question, .push() is not identical to .add().

    The .push() method is for adding a DOM element to an existing jQuery object.

    The .add() method can accept a DOM element, or another jQuery object with 1 or more DOM elements, and it returns a new jQuery object with the new elements added.

    It’s more like a .concat().

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

Sidebar

Related Questions

I have tried to do a test: var test = Array(); $('input[name=first_category[]]:checked').each(function() { test.push($(this).val());
var objs = new Array(); function Foo(a) { this.a = a $(#test).append($(<button></button>).html(click).click(this.bar)); } Foo.prototype.bar
I have a JavaScript array that can be built using this code var Test
Hello i have this method: private function findConnectedNodes(node:Node):Array{ var test_node:Node; var surrounding_nodes:Array = [];
I have DocumentRoot /var/www/test in my .htaccess file. This is causing the apache server
why does this only alert 1 ? function test() { var myobj = {
var x= 1; Number.prototype.test = function () { return this }; x.test() === x.test()
My aim is to get a json array like this one: var args =
I currently have this: $.getJSON('test.json', function(data) { var items = []; $.each(data, function(key, val)
How come this works: var items = []; $.each([1, 2, 3, 4], function ()

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.