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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:22:53+00:00 2026-06-14T00:22:53+00:00

I am trying to push elements onto an array. EDIT task.prototype.goTest=function(){ for(a = 0;

  • 0

I am trying to push elements onto an array.

EDIT

 task.prototype.goTest=function(){

     for(a = 0; a < test.length; a++) {
        if(this.testnumber != test[a].number) {

            //it will only loop 8 times under conditional statement            
            group = {
                title: test[a].Title,
                ID: test[a].ID,
                contents: []
            };

            this.company.push(group);
            this.testnumber = test.number[a];
        }
        //outside of if conditional statement.. it will loop 15 times
        //i want every test[a].conetents get pushed to group.contents array. 
        //this.company is the final variable I need for this function...    

        group.contents.push(test[a].contents);
    }
    console.log(this.company);
}

However, when I do

console.log(this.company);

I see 8 elmements with only 1 element in each group.contents array. The ideal situation is to have 8 elements with 2 to 3 elements in the group.contents array.

this refers to the object in the function.
Any idea how to solve my issue?

  • 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-06-14T00:22:55+00:00Added an answer on June 14, 2026 at 12:22 am

    You are making a new group object each loop, so the reference to group.contents is only the current one, it does not reference the previously created group objects.

    So, each time you call group.contents.push, you are only pushing onto the object created in that loop iteration.

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

Sidebar

Related Questions

I am trying to add all the elements in array using push . then
I am getting this error when I am trying push my files into heroku
I'm trying to push a Lua class object onto the stack. The pointer to
I'm trying to populate a multidimensional array (array with array elements) via Javascript or
when I'm trying to push elements to a stack I get segmentation fault, but
I'm trying to add elements to an array after subsequent trials, but so far
I am trying to update multiple elements at once in a multidimensional array/object and
I am trying to access elements of an array which is part of a
I was trying to group a set of INPUT-elements in a Javascript array and
Im trying push some data into a CRM system via an XML import. I

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.