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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:44:00+00:00 2026-05-26T15:44:00+00:00

I would like to know the correct way to create a nested object in

  • 0

I would like to know the correct way to create a nested object in javascript. I want a base object called “defaultsettings”. It should have 2 properties (object type): ajaxsettings and uisettings. I know that i can write something like

var defaultsettings = new Object();
var ajaxsettings = new Object();

defaultsettings.ajaxsettings = ajaxsettings.. etc.

But what i want to know is how to type it this way (that i suppose is a more correct way of doing it):

var defaultsettings = { 
    var ajaxsettings = { ... }
};

I suppose you get the idea. Thanks!

  • 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-26T15:44:00+00:00Added an answer on May 26, 2026 at 3:44 pm

    If you know the settings in advance you can define it in a single statement:

    var defaultsettings = {
                            ajaxsettings : { "ak1" : "v1", "ak2" : "v2", etc. },
                            uisettings : { "ui1" : "v1", "ui22" : "v2", etc }
                          };
    

    If you don’t know the values in advance you can just define the top level object and then add properties:

    var defaultsettings = { };
    defaultsettings["ajaxsettings"] = {};
    defaultsettings["ajaxsettings"]["somekey"] = "some value";
    

    Or half-way between the two, define the top level with nested empty objects as properties and then add properties to those nested objects:

    var defaultsettings = {
                            ajaxsettings : {  },
                            uisettings : {  }
                          };
    
    defaultsettings["ajaxsettings"]["somekey"] = "some value";
    defaultsettings["uisettings"]["somekey"] = "some value";
    

    You can nest as deep as you like using the above techniques, and anywhere that you have a string literal in the square brackets you can use a variable:

    var keyname = "ajaxsettings";
    var defaultsettings = {};
    defaultsettings[keyname] = {};
    defaultsettings[keyname]["some key"] = "some value";
    

    Note that you can not use variables for key names in the { } literal syntax.

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

Sidebar

Related Questions

Would like to know what a programmer should know to become a good at
I would like to know what would be the best way to do unit
I would like to know if there is any way to add custom behaviour
I want to create a database query string which should be like this, (SELECT
I would like to know if my approach is correct for a website that
I would like to know people's thoughts on the best way to do the
i would like know some reference. I know i can googling it. but prefer
Would like to know the c# code to actually retrieve the IP type: Static
I would like to know if I can open 2 different diagrams using MS
I would like to know which dependency described in my pom.xml brings a transitive

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.