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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:52:49+00:00 2026-06-07T05:52:49+00:00

Well, I’m so confused. I have made a json element like this: var world

  • 0

Well, I’m so confused. I have made a json element like this:

var world = {"county": []};
world.county.push({name: "America", flag: "yes", countries: []});
world.county[0].countries.push({name: "Costa Rica", capital: "San Jose"});

This leads me to think two things:

  1. I’m mixing arrays with json objects. How can I avoid using arrays in this scenario?
  2. How can I add elements to the json root dynamically?

Regarding question 2, I’m facing issues because I don’t know how to add elements to the root, let’s say that I have tried this, but it doesn’t work:

var index = 0;
var word = {};
world.index.push({name: WA});

So, by this way I could add elements iterating some array created previously.

  • 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-07T05:52:50+00:00Added an answer on June 7, 2026 at 5:52 am

    Start with Kolink’s answer. Then, for what you are doing here:

    var index = 0;
    var world = {};
    world.index.push({name: "WA"});
    

    It looks like you are trying to add a property to world with the index 0. Given you are then trying to use .push() it would seem you want that property to be an array, in which case you would do that like this:

    world[index] = [];
    world[index].push({name: "WA"});
    

    Given that world started as an empty object that would create this structure:

    { "0" : [ {name:"WA"} ] }
    

    In a general sense, to access an object property where the property is in a variable you use the [] array-style syntax. So:

    world["somePropName"]
    // does the same thing as
    world.somePropName
    // so with a variable:
    var x = "somePropName";
    world[x]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

well i have a configuration like this in the components part of my config
well i have used an html file like these in iframe <iframe src=sample.html></iframe> is
Well, this is an interesting problem. I have an ASP.NET MVC3 Intranet application running
Well, I have to revive a question that was answered here before. I've made
Well, I have GridView with editable field like 'TemplateField' with DropDownList. My code: <Columns>
Well I have a view of this type of hierarchy Main View (having some
Well i have var message , which has any type of character... I replace
Well friends, I have got this query which works but is very long for
Well I made this game in java and when you shoot a bullet it
Well, this is my first post here and really enjoying the site. I have

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.