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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:54:29+00:00 2026-05-30T12:54:29+00:00

I need to create a dynamic array with a loop.. but I cant seem

  • 0

I need to create a dynamic array with a loop.. but I cant seem to get the desired results.

the array I want is:

{
    "CategoryName": "somecategoryname",
    "Date": "02-17-2012",
    "Id": 24,
    "ProductToHide": [
        {
            "IsHide": true,
            "ProductId": "someid"
        }
    ],
    "ProductsToAdd": [
        {
            "MealSequence": "S1",
            "ProductId": "Someid"
        },
        {
            "MealSequence": "S2",
            "ProductId": "Snack_11"
        }
    ],
    "UserId": "1"
}

and I am using the following function to add products:

addProduct: function(id){
        var tempArr = [];
        $.each(this.mCData.ChildCategories, function(i, item){
            $.each(item.PList, function(j, jsonPr){
                if (jsonPr.TID == id){
                    addProduct = new mealTypeProduct();
                    addProduct.data = jsonPr;
                    tempArr = addProduct.modifyProduct();
                }   
            })
        })

    //  queryStr = {"add" : tempArr};
    //  this.modificationArray.push(queryStr);
        this.modificationArray['add'].push(tempArr);    
        console.log(this.modificationArray);
    }

Its giving me the following error:

this.modificationArray.add.push is not a function
this.modificationArray['add'].push(tempArr);

the initializing is done in the following manner:

var mealType = {
    chosenDate: new Date(), tabViewHtml: '',
    modificationArray: [], saveArray: [],
}

What am I doing wrong?

  • 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-30T12:54:31+00:00Added an answer on May 30, 2026 at 12:54 pm

    This line:

                    tempArr = addProduct.modifyProduct();
    

    replaces tempArr with a new value, so at the end of the $.each call it will have the value from the last matching product (which may not be an array) rather than being an array of all of them. If that is what you want then that’s not a problem.

    As to the actual error you quote: what type of thing is this.modificationArray? Does it have a member called add? Does that member have a push() function? Is it initialized properly, or is it left uninitialized? If the latter, then there’s your problem: you need to initialize it before you can call push().

    UPDATE: If this.modificationArray is initialized as [], as in the new sample code, then it is an array itself; it does not have an add member. The code should say this.modificationArray.push(tempArr).

    Alternatively, if you really do want an add member, then this.modificationArray should be initialized as modificationArray : {add:[]}

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

Sidebar

Related Questions

I need to create a dynamic array in Java, but the values type differ
I want to create a dynamic 2d array by function but it seems that
HI all, i need to create an dynamic array, every time i add object,it
I want to resize my array dynamic. Everything would be ok, but in example
Is it possible to create a dynamic array using something like this and store
i need to create a dynamic SQL statement that selects fields based on an
I need to have a dynamic array, so I need to allocate the necessary
I'm trying to create an associative array with dynamic data, and having some trouble.
What would be the best way to create a dynamic array for a user
I have a dynamic SQL statement I've created in a stored procedure. I need

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.