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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:59:13+00:00 2026-05-30T22:59:13+00:00

i have an array and an object. var myObj = { abc: 200, xyz:

  • 0

i have an array and an object.

var myObj = { "abc": 200, "xyz": 300};
vay myArray = ["one", "two"]

i want to next the values of myObj inside “one”.

so myArray[0] would return object data-

the console.log(myArray) would look something like.

-"one"
    *Object
            *abc:200
            *xyz:300
-"two"

i tried using push to add myObj to myArray[0], but it did not work.
Any suggestions.

Update:
My code looks like this now, maybe this will help me ask correctly:

var allData = {
user1:[userData]}

this runs each time a function is called.

userData the first time is ex: {name:bob, id:123} and {name:dave, id:456} the second time the function runs.

but if i do a console.log{allData), i only see the last userDat objecta. i would like it to add on to the user1 each time i use the function so that i could essentially do the following allData.user1[1].name; and get “dave”

  • 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-30T22:59:15+00:00Added an answer on May 30, 2026 at 10:59 pm

    The following structure is what you seem to be asking for:

    var myArray = [
                    { "one" : { "abc": 200, "xyz": 300} },
                    "two"
                  ];
    

    That is, the first element in the array becomes an object that has one property named “one”, and the property references the object { "abc": 200, "xyz": 300}. The second element in the array is still just a string, “two”.

    To access the “abc” property you’d say myArray[0]["one"]["abc"] or myArray[0].one.abc. This seems kind of clunky and perhaps isn’t at all what you want, but as I said it’s what you seem to be asking for.

    If the object and array both already exist as shown in your question and you want to use the current value of array element 0 to be the key in the object you can do this:

    var myObj = { "abc": 200, "xyz": 300},
        myArray = ["one", "two"];
    
    var tempObj = {};
    tempObj[myArray[0]] = myObj;
    myArray[0] = tempObj;
    

    It seems to me that a more sensible structure would be:

    var myObj = {
           "one" : { "abc": 200, "xyz": 300 },
           "two" : null
    };
    

    So that you can simply say myObj["one"]["abc"] or myObj.one.abc.

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

Sidebar

Related Questions

I have converted an array to object data like this: <?php $myobject->data = (object)Array('zero','one','two');
if we have a javascript object var calories = { apple:200, pear:280, banana:300, peach:325
I have an associative array (object) of the following construction var menu = new
I have code: api_result = '{response:[{uid:1969258,first_name:Walle,last_name:Woo}]}'; var myobj:Object = JSON.decode(api_result); So, how I can
If I have an object defined as: var myObj={}; Then, I update this object
I have an object array and I want to convert it to a specific
I have dynamic array (object) var variables = {}; variable[var1] = someValue; variable[var2] =
I have an array of object literals like this: var myArr = []; myArr[0]
I javascript I have an object that looks similar to: var myObj = {
I have this object/array thing: var states = {}; states[CA] = new State(CA, California);

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.