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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T19:51:47+00:00 2026-05-16T19:51:47+00:00

I have a JavaScript object that I’d like to add some properties to, but

  • 0

I have a JavaScript object that I’d like to add some properties to, but I don’t know what the names of the properties are until runtime.

Can I do this without using eval? If so, how?

var get_params = new Object();
var params = {'name':'john', 'age':'23'}; //actually not known until runtime
for (var i=0, len=params.length; i<len; ++i ){                                                  
        get_params.p[0] = p[1]; //How can I set p[0] as the object property?
    }
}
  • 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-16T19:51:48+00:00Added an answer on May 16, 2026 at 7:51 pm

    Since your code example has a malformed array, I will include 2 variations.

    Variation 1 (params is an actual object and not an array):

    var get_params = {}; // prefer literal over Object constructors.
    
    var params = {'name':'john', 'age':'23'}; // @runtime (as object literal)
    
    for (var key in params){
        if(params.hasOwnProperty(key)) { // so we dont copy native props
            get_params[key] = params[key];
        }
    }
    

    Variation 2 (param is an array containing objects):

    var get_params = {}; // prefer literal over Object constructors.
    
    var params = [{'name':'john'},{'age':'23'}]; // @runtime (as array literal)
    
    for(var i=0,param;param=params[i];i++) {
        for (var key in param){
            if(param.hasOwnProperty(key)) {
                get_params[key] = param[key];
            }
        }
    }
    

    Enjoy.

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

Sidebar

Related Questions

In javascript, I have an object that I am trying to pass but not
I have a javascript object that I would like to update with data from
I have a Javascript object that I want to pass in more parameters, but
I have a JavaScript object that does something like this - using a closure
I have a JavaScript object that looks something like this: var myTextOptions = {
If I have a javascript object that looks like the following: { 0: [0,50],
I have a javascript object, that could be something like this { users: [{
I have a Javascript object that registers for the mouse move event. But my
I have a Javascript object that (very simplified) looks like this if('undefined' !== typeof(listCtrls)){
I have an javascript object that contains a select list. I'd like to loop

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.