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

The Archive Base Latest Questions

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

Why does javascript allow me to do the following. a = {two : ‘World’};

  • 0

Why does javascript allow me to do the following.

a = {two : 'World'};
a[1] = 'Hello';
console.log(a[1]);
console.log(a.two);

the output is

Hello
World

Shouldn’t it complain that I am trying to use an object as an Array? This works with anything by the way, like so

b = new Date();
b[1] = 'Wow';
console.log(b[1]);

the output is

wow

Is there a use for this? It seems to me like a bad programing practice.

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

    In Javascript, all arrays are objects. There is no hard-and-fast dividing line between the two. Arrays have certain properties and methods, but are implemented as objects.

    The syntax [1] is one of the two equivalent Javascript member operators. These two are equivalent:

    var foo = {};
    foo.bar = 'foobar';
    foo['bar'] = 'foobar';
    

    However, with the dot notation (foo.bar), you can only access properties that are valid Javascript identifiers. This means:

    a sequence of alphanumerical characters, also including the underscore (“_”) and dollar sign (“$”), that cannot start with a number (source)

    You can set the properties of any Javascript object — array, object, Date object, string, number — in this fashion, since they all derive from the same Object type.

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

Sidebar

Related Questions

Firefox 3.5 does not allow creating java OBJECT tag with Javascript (document.write)? this technique
Does jquery/javascript have any event model that you can attach to your objects? Basically
Which algorithm does the JavaScript Array#sort() function use? I understand that it can take
Consider languages like Python or JavaScript that allow functions to be nested like this:
Does anyone know of a project that will allow the editing of a language
Does any one know of any good javascript 3d graphing utility? I know that
I'm creating a Firefox add-on that does the following: Drag+drop a file into Firefox
Awhile back, I found the following javascript function that allows you to dynamically add
I am try to write a regular expression in javascript that will not allow
Does javascript coding work better with any particular server language?

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.