Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

117
Views
Dynamically create or modify objects within a object

I'm currently creating a grocery-list sorting app and ran into an issue. Because the aisle locations vary from store to store I need to dynamically create objects and add all items in that aisle to the corresponding aisle object.

I don't have a lot of experience creating/modifying objects, so I'm not sure how to approach this.

I'm looking for a result like this:

{
  aisles:
    {
      1:
        {[
           'pizza',
           'ice cream',
        ]}
      2:
        {[
           'tissues',
           'toilet paper',
        ]}
    }
}

Can anyone help me with this?

Thanks so much.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The code above won't run because there are no keys for the inner most object containing arrays. You can do remove the inner most object and leave it as an array.

objectName = {
          aisle: {
             1:  ['pizza', 'ice cream'],
             2:  ['tissue', 'toilet paper']
          }
}

To dynamically add data you can use a function.

function addValues(key, value){      
  objectName.aisle[key] = value;
}

Now you can call the method to add data into the objectName.

addValues("3", ["data","data"]);
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!