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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:19:32+00:00 2026-06-15T02:19:32+00:00

I notice a difference when I declare a variable as an array or object

  • 0

I notice a difference when I declare a variable as an array or object and then add elements to it.

When I declare my variable as below:

var my_array = [];
my_array["a"] = 'first';
my_array["b"] = 'second';
console.log(my_array);

I get the following result:

[a: "first", b: "second"] 

However, when I do the following:

var my_array = {};
my_array["a"] = 'first';
my_array["b"] = 'second';
console.log(my_array);

This is the result I get:

Object {a: "first", b: "second"} 

What is really going on here?! Is one way standard, and the other not?! What are the downsides with compatibility?!

Thanks in advance.

P.S. I’m using Google Chrome.

  • 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-15T02:19:33+00:00Added an answer on June 15, 2026 at 2:19 am

    The first is an array and the secound is an object, which one to use depands on your goal, if you need arrays the array will be more usefull and effiecent than using an “array” object.

    Further more an object can be used like this:
    myObject.a

    While an array can be only used like this: myArray["a"]

    Another diffrence is in the toString method. For an array it returns Banana,Orange,Apple,Mango (for example) and for an object it returns [object Object](for example).

    For further reading: What is the difference between an array and an object?

    Check if is array:

    function isArray(obj) {
        return Object.prototype.toString.call(obj) === "[object Array]";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a bit confused about the difference between when I just declare a variable
Is there a programmatic benefit to using a using statement? Notice the difference between
Gingerbread (2.3.3) emulator left, ICS (4.0.3) emulator right. Notice the gradient fade effect difference
While perusing some Apple Header files, I notice that they declare multiple interfaces using
I notice in the MSDN documentation that there are multiple ways to declare a
Can someone please explain to me why I get Notice: Undefined variable for variable
The title explains it all. What's the difference? var $foo; $bar; What's the main
I noticed that in shell script when we declare a variable, the preceding dollar
I've noticed a difference between the returns from boto's api depending on the bucket
I've noticed a behavior difference between static and dynamic resource on ComboBox.ItemsSource, when the

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.