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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:13:16+00:00 2026-06-10T04:13:16+00:00

Possible Duplicate: Objects vs arrays in Javascript for key/value pairs I have a variable

  • 0

Possible Duplicate:
Objects vs arrays in Javascript for key/value pairs

I have a variable in JavaScript which I am using like a hash. I can initialize it like:

var selected = [];

or

var selected = {};

and it does the same exact thing. I’m using it like this for example:

selected["one"] = 1;

if (selected["one"] == 1) console.log("one is selected"); 
// result: one is selected

if (selected["two"] != 1) console.log("two is not selected");
// result: two is not selected

selected["one"] = 0;

if (selected["one"] != 1) console.log("one is no longer selected");
// result: one is no longer selected

Is there really a difference? Is one an object and the other an array ? If so, when should I expect to run into problems. Ie., what is the difference between the two in their usage, and why would you chose one over the other?

  • 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-10T04:13:17+00:00Added an answer on June 10, 2026 at 4:13 am

    [] is an array, {} is an object. An array is a type of object intended to be only assigned numeric keys.

    While you can in theory use them interchangably, look what happens when you JSON-ify them:

    var tmp = []; // or: var tmp = {}
    tmp.one = 1;
    JSON.stringify(tmp);
    
    // array:
    '[]'
    
    // object:
    '{"one":1}'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Loop through associative array in reverse I have a key-value pair javascript
Possible Duplicate: Length of Javascript Associative Array I have a JSON that looks like
Possible Duplicate: How to sort an array of javascript objects? i have a array
Possible Duplicate: In javascript how can we identify whether an object is a Hash
Possible Duplicate: How to sort an array of javascript objects? I have output that
Possible Duplicate: indexOf method in an object array? I have a javascript array which
Possible Duplicate: How to properly clean up Excel interop objects in C# I have
Possible Duplicate: C++ delete - It deletes my objects but I can still access
Possible Duplicate: What is the 'new' keyword in JavaScript? creating objects from JS closure:
Possible Duplicate: javascript object, access variable property name? I'm trying to call a method

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.