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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:42:32+00:00 2026-06-03T04:42:32+00:00

In a program i am writing i need an object variable that looks like

  • 0

In a program i am writing i need an object variable that looks like this:

var map {
    cube: {__pt3arraylocation__:[0,0,0], poly: new Object()},
    other: {__pt3arraylocation__:[1,0,0], poly: new Object()}
};

However, i want to be able to type map.cube and have it return the pt3arraylocation as a default unless i specify what i want by typing map.cube.poly

for example: map.cube would return [0,0,0] and map.cube.poly would return the object poly in the object cube

thanks in advance

  • 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-03T04:42:33+00:00Added an answer on June 3, 2026 at 4:42 am

    i want to be able to type map.cube and have it return the pt3arraylocation as a default unless i specify what i want by typing map.cube.poly

    for example: map.cube would return [0,0,0] and map.cube.poly would return the object poly in the object cube

    You can’t do that in JavaScript.

    However, as an alternative, it’s worth noting that you can add arbitrary properties to arrays if you want to. So for instance:

    var map {
        cube:  [0,0,0],
        other: [1,0,0]
    };
    map.cube.poly = {};  // {} is the same as `new Object()` but not subject to people...
    map.other.poly = {}; // ...overriding the `Object` symbol
    

    Then map.cube gives you the array, and map.cube.poly gives you the object you’ve stored on that array.

    How is this possible? Because in JavaScript, arrays aren’t really arrays. They’re just objects that have an automatic length property, treat a class of property names (all numeric ones) in a special way, and have Array.prototype backing them up. And of course, you can add properties to any object.

    There’s no literal syntax for doing this, which is why I had to do it with assignments after the object initializer above. But it’s perfectly valid. I use it for cross-indexing arrays all the time.

    Do be sure, if you do this, that you’re not using for..in incorrectly; more.

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

Sidebar

Related Questions

As part of the program that I am writing I need it to: Compare
I'm writing a program in C# that will need to store a few Data
I am writing a program that needs to run a java.jar server. I need
I am writing a small program that gets activated when sms is received.We need
I'm writing a program that has two libraries that I need to use: v8,
I'm writing a program using jdbc that will be an interface to database(smth like
I am writing a program in C# that needs to support undo/redo. For this
I'm writing a program which is more or less like this : #include <list>
My program that I am writing's purpose arose with this issue: There are two
I am writing a program in C++ and I need to initialize an array

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.