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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:27:32+00:00 2026-06-13T16:27:32+00:00

This is done in the node shell: > results = [] [] > num

  • 0

This is done in the node shell:

> results = []
[]
> num = 5
5
> results[num] = []
[]
> results
[ , , , , , [] ]
>

And even if I try to stringify the number:

> results = []
[]
> num = 5
5
> results[num.toString()] = []
[]
> results
[ , , , , , [] ]
> results['5'] = []
[]
> results
[ , , , , , [] ]
>

It would seem that javascript is interpreting a string as a number in the definition of an object?

I’d like the results to look like this:

results = [ { '5' : [
                   { key : value },
                   { key2 : value }
                  ]
            }
          ]
  • 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-13T16:27:34+00:00Added an answer on June 13, 2026 at 4:27 pm

    You’re not working with just any kind of object. [] is an Array, and has certain magical properties — one of them being that non-negative integer-looking keys extend the array. Even if they’re strings, that doesn’t matter — all object keys are strings anyway, and arrays are still objects.

    Try using {} rather than [] if you don’t want arrays’ special treatment of integer-looking keys.

    > results = {}
    {}
    > results[5] = []
    []
    > results
    { '5': [] }
    

    Course, if you’re looking to make the value a bunch of key/value pairs as well, you might consider saying results[5] = {}.

    > results = {}
    {}
    > results[5] = {}
    {}
    > results[5]['key'] = 'value'
    'value'
    > results
    { '5': { key: 'value' } }
    > results[5]['key2'] = 'value'
    'value'
    > results
    { '5': { key: 'value', key2: 'value' } }
    

    The []s you’re asking for seem kinda broken in most cases. Javascript objects are by their very nature dictionaries, and having a list of them with one key/value pair each seems to add complexity without real gain. The exception would be if you want to have a bunch of values per key and are willing to put up with the added ugliness of having to loop through the whole list of pairs each time you want to find something.

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

Sidebar

Related Questions

I'm looking for a simple way to have this done. I would to have
Looking for a node.js package that handles stack tracing similar to how this is
Sure I've seen this done before but off-hand I can't find any examples. I've
I've seen this done with a signed Java Applet, but is it possible with
I've seen this done before, but I'm not sure how. When my page loads,
I've seen this done inside of an event handler directly behind the .xaml file
I think I've seen this done once, but I cannot find it again after
I am sure someone has this done already, and was hoping someone could share
Ok so I have looked up several ways of getting this done, and none
I am not an expert in Git, but I have seen this done before

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.