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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:39:32+00:00 2026-06-10T12:39:32+00:00

Crockford writes in http://javascript.crockford.com/survey.html : There are two ways to make a new array:

  • 0

Crockford writes in http://javascript.crockford.com/survey.html:

“There are two ways to make a new array:

var myArray = [];
var myArray = new Array();”

So I’m confused by these two lines in some AJAX code I am reading:

var obj={};    // obj is an Object object (i.e. a hash table)
obj[4] = 'x';  // now obj is suddenly an Array object via an integer key?

In JavaScript are an object and an array really just the same thing, but with a variant on the key type?

In other words, is this the same as in php where we can use either a name (string) or an integer for a hash key?

I’ve Googled for an answer on this but can’t seem to nail down an article which discusses this issue.

One possibility that comes to mind is that perhaps the first line is syntactic lint because the 2nd line overwrites the previous definition of obj as it creates a new Array object.

  • 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-10T12:39:34+00:00Added an answer on June 10, 2026 at 12:39 pm

    As far as I know, no, an object can’t be coerced into an array. But, it can look and act like an array, and that’s what’s happening here. Numbers, and anything else that can be coerced to a string, are perfectly valid property names for Javascript objects, so

    obj[4] = 1;
    obj['spam'] = 2;
    

    are both valid ways of setting a property on the object. That doesn’t make the object an array. An Array is a special class of object with specific methods (.slice(), .concat(), etc) and a length property that’s kept up to date with the number of items in the array.

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

Sidebar

Related Questions

I read crockford's page on private members http://javascript.crockford.com/private.html in Javascript and got a question
I was reading Crockford's tutorial http://javascript.crockford.com/private.html . private variables are implemented by function inside
I've been playing around with prototypal inheritance after reading http://javascript.crockford.com/prototypal.html and having a bit
Douglas Crockford himself says so ! http://www.crockford.com/javascript/javascript.html I have been working with JS only
Using Crockford's method ( http://javascript.crockford.com/prototypal.html ) doesn't work when we have reference values in
Douglas Crockford says: JavaScript is a sloppy language, but inside it there is an
I remember reading in Douglas Crockford's Javascript the Good Parts book that there is
I'm actually studying Crockford's Javascript: the good parts . I am new to JavaScript
Crockford had this example to keep myArray from being in the global scope: var
This is code from Crockford's JavaScript: The Good Parts. var results = []; var

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.