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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T23:29:07+00:00 2026-06-02T23:29:07+00:00

I would want to set the elements of an array of a struct in

  • 0

I would want to set the elements of an array of a struct in its creation. Is it possible?

Now, in the first I’ve to define the struct and then set the array

function struct(a, b) {
    this.a=a;
    this.b=b;
}

var foo = [
    new struct(1,2),
    new struct(3,4),
]

but I would want an anoynymous function, anything like:

var foo = function(a, b) [
    (1,2),
    (3,4),
]

Note: it’s incorrect but you see the idea

  • 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-02T23:29:08+00:00Added an answer on June 2, 2026 at 11:29 pm

    What you want to use is the object literal notation in addition to the array literal notation.

    var foo = [
      {a:1,b:2},
      {a:3,b:4}
    ];
    console.log(foo[0].b); //-> 2
    

    If you really want to call a function, you have to give it a name (though it can be a short one):

    function s(a,b){
      return {a:a,b:b};
    }
    var foo = [
      s(1,2),
      s(3,4)
    ];
    

    You don’t need to use the new keyword to create a new object; you can set up a new instance—and even set the prototype-based inheritance—all within a normal function call.

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

Sidebar

Related Questions

I have an array, int a[size]; I want to set all the array elements
I would like to programmatically set maxLength property of TextView as I don't want
I have a set of .csv files that I want to process. It would
I would want to search up, down, and match case if possible. Even links
I would want to create a table with the same widths (table and its
I'm writing a PHP web service and one function. I want to set up
This question is related to Array of pairs of 3 bit elements This array
Is it possible to create a dynamic array using something like this and store
I have n elements in a set U (lets assume represented by an array
Why would someone want to use a linked-list over an array? Coding a linked-list

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.