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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:42:33+00:00 2026-06-04T05:42:33+00:00

I am very new to JS, have been working in C/C++ before, I need

  • 0

I am very new to JS, have been working in C/C++ before,
I need an equivalent of below C structure in JSON

struct tmp_t{
int a;
char c_str[1024];
};

struct tmp2_t{
int a2;
.
.
char c2_str[1024];
};

struct my {
int number;
struct tmp_t tmp[100];
struct tmp2_t tmp2[100][1000];
};

For a json like

var myJSON = {
"number":0,
.
.
};

I need to access it like

myJSON.tmp[0].a = 10;
myJSON.tmp2[0][1].c2_str = "hello world"

any input is highly appreciated

  • 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-04T05:42:34+00:00Added an answer on June 4, 2026 at 5:42 am

    Javascript properties are not typed like they are in C so there is no purely “equivalent” expression in javascript. You don’t predeclare typed data structures like your C code has. I given variable or property in javascript can be assigned any value or reference – there is not hard typing. So without variables that can only contain a specific type like C has, there’s no pre-declaring of data structure definitions like you have included from C.

    Instead, you just declare the properties you want to use on a live object or if you intend to use many of them, you can create a prototype which you can instantiate when needed.

    A direct declaration of a live object instance somewhat like your last structure would look like this:

    var my = {
        number: 10,
        tmp: new Array(100),
        tmp2: new Array(100)
    };
    

    This would declare an object named my that had three properties called number, tmp and tmp2. number initially contained the number 10 and the other two properties contained arrays of length 100 who’s values were undefined. I don’t know of any compact way to predefine your two dimensional array in javascript without running code in a loop to initialize it.

    This data defintion would let you access my.number, my.tmp and so on.

    If you want your arrays to contains objects with properties themselves, then you need to populate those arrays with the objects.

    var my = {
        number: 10,
        tmp: [{a: 1, c_str: "foo"}, {a: 2, c_str: "whatever"}],
        tmp2: new Array(100)
    };
    

    Or, in code, you could add in item to the tmp array with code like this:

    var my = {
        number: 10,
        tmp: [],
        tmp2: []
    };
    
    my.tmp.push({a: 1, c_str: "foo"});
    my.tmp.push({a: 2, c_str: "whatever"});
    

    Or, you could create the object separately and then put it in the array:

    var obj = {};        // new empty object
    obj.a = 1;           // assign property
    obj.c_str = "foo";   // assign property
    my.tmp.push(obj);    // put object into the array
    obj = {};            // new empty bject
    obj.a = 2;
    obj.c_str = "whatever";
    my.tmp.push(obj);
    

    Or, you could assign each property individually like this:

    my.tmp.push({});           // put empty object into the array
    my.tmp[0].a = 1;           // assign property to the object
    my.tmp[0].c_str = "foo";   // assign property to the object
    my.tmp.push({});
    my.tmp[1].a = 2;
    my.tmp[1].c_str = "whatever";
    

    In either case, you could then access the data like this:

    console.log(my.tmp[0].a);       // 1
    console.log(my.tmp[0].c_str);   // "foo"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am very new to javascript and ajax/jquery and have been working on trying
Sorry I am very new to open graph and have been having difficulty to
Im very new to all coding including jquery. I though this would have been
I'm very much new to programming and have been doing fairly well so far.
I'm a new user to knockout.js and so far have been very impressed with
Very new to python and can't understand why this isn't working. I have a
I have been working with PHP for years and gotten a very good grasp
I'm very new to AS3 and I have been stuck with this problem for
I'm somewhat new to Rails and have been working with the scopes in Rails
I am learning Android and have been working on an application that will need

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.