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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:23:15+00:00 2026-05-31T07:23:15+00:00

I find myself making (potentially) more work for myself, by having to specify each

  • 0

I find myself making (potentially) more work for myself, by having to specify each dynamic key one line at a time.

What I am doing now to add additional keys to an existing object:

create_request[('title_' + id)] = field_data[0];
create_request[('field_' + id)] = field_data[1];

What I was hoping to be able to do is something like:

jQuery.extend({('title_' + id) : field_data[0], ('field_' + id) : field_data[1]});

Is there an easier way than what I am doing now (since what I was hoping would work doesn’t)? Or is this just a limitation of the language?

Edit for clarity:

Okay, so you can create an object in javascript like this:

{
 a : 1
}

But that assumes that a is the string value for the key. What if I wanted the key to be the value of a variable?

I could do:

the_object[variable] = 1

But what if I wanted to do more than one of these dynamic insertions into the object? Is there a convenient way to do that?

  • 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-31T07:23:16+00:00Added an answer on May 31, 2026 at 7:23 am

    If I could change just one thing about JavaScript, it would be object literal syntax. I think the property names should be evaluated as expressions the same as the property values; I think the benefits of this would outway the nuisance of being forced to include quoted property names when using static names. But, if wishes were fishes…

    Using the square-bracket notation is the only built-in way to set properties with dynamic names, but it is not difficult to create your own function that takes input very similar to the syntax you hoped to use:

    extendObject(obj, props) {
       for (var i = 0; i < props.length; i+=2)
          obj[props[i]] = props[i+1];
    }
    
    extendObject(create_request, ['title_' + id, field_data[0], 'field_' + id, field_data[1]]);
    

    By using an array rather than a plain object to hold the new property names and values you can use dynamic names.

    (Note also that even with the square-bracket syntax in your question you’ve made it slightly more complicated than it needs to be by including redundant parentheses.)

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

Sidebar

Related Questions

I find myself making repetitive mistakes typing keywords and sentences in my code comments.
I find myself needing to store public key certificates, and a single private key
Every now and again I find myself doing something moderately dumb that results in
I frequently find myself making a dummy console app to test something simple out.
When I'm making user controls for both Winforms and ASP.NET, I find myself writing
I'm starting to find myself getting more and more in to using WCF for
I often find myself using several programming languages when making .NET applications. Usually C++/CLI
So I find myself doing something like the following pattern often. Instead of: if
As I develop more with vim, I find myself wanting to copy in blocks
I find myself in the unique position of having to find a suitable 2D

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.