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

  • Home
  • SEARCH
  • 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 8607861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:28:00+00:00 2026-06-12T03:28:00+00:00

I am having trouble in making array in javascript. First I made like this

  • 0

I am having trouble in making array in javascript. First I made like this

for(var i=1; i <= rowCount-1; i++)
    {  
        product[i-1] = [{
            'product_id' : $('#product_id' + i).val(),
            'name' : $('#item' + i).val(),
            'model' : $('#model' + i).val(),
            'reward' : $('#reward' +i).val(),
            'subtract' : $('#subtract' + i).val(),
            'minimum' : $('#minimum' + i).val(),
            'shipping' : $('#shipping' + i).val(),
            'tax_class_id' : $('#tax_class_id' + i).val(),
            'weight' : $('#weight' + i).val(),
            'quantity' : $('table.order-table tbody tr td.quantity input[name=\'quantity'+ i +'\']').val(),
            'price' : $('table.order-table tbody tr[id=\''+ i +'\']').find('td.price').html(),
            'total' : $('table.order-table tbody tr td.quantity input[name=\'quantity'+ i +'\']').parent().parent().find('td.total').html()
        }];
    }

After passing it as argument in ajax post I can see that it passing it as

product[0][0][minimum]  
product[0][0][model]    326
product[0][0][name] apple mac power
product[0][0][price]    100.0000
product[0][0][product_id]   50
product[0][0][quantity] 5
product[0][0][reward]   0
product[0][0][shipping] 1
product[0][0][subtract] 1
product[0][0][tax_class_i...    0
product[0][0][total]    500
product[0][0][weight]   0.00000000
product[1][0][minimum]  
product[1][0][model]    326
product[1][0][name] apple mac power
product[1][0][price]    100.0000
product[1][0][product_id]   50
product[1][0][quantity] 7
product[1][0][reward]   0
product[1][0][shipping] 1
product[1][0][subtract] 1
product[1][0][tax_class_i...    0
product[1][0][total]    700

but I want something like this

product[0][name] = "apple mac power"

so I changed my code to this

for(var i=1; i <= rowCount-1; i++)
{  
    product = [{
        'product_id' : $('#product_id' + i).val(),
        'name' : $('#item' + i).val(),
        'model' : $('#model' + i).val(),
        'reward' : $('#reward' +i).val(),
        'subtract' : $('#subtract' + i).val(),
        'minimum' : $('#minimum' + i).val(),
        'shipping' : $('#shipping' + i).val(),
        'tax_class_id' : $('#tax_class_id' + i).val(),
        'weight' : $('#weight' + i).val(),
        'quantity' : $('table.order-table tbody tr td.quantity input[name=\'quantity'+ i +'\']').val(),
        'price' : $('table.order-table tbody tr[id=\''+ i +'\']').find('td.price').html(),
        'total' : $('table.order-table tbody tr td.quantity input[name=\'quantity'+ i +'\']').parent().parent().find('td.total').html()
    }];
}

So after doing this it is showing only array of 1 row no matter of how many rowCount I have like this

product[0][minimum]  
product[0][model]    326
product[0][name] apple mac power
product[0][price]    100.0000
product[0][product_id]   50
product[0][quantity] 7
product[0][reward]   0
product[0][shipping] 1
product[0][subtract] 1
product[0][tax_class_i...    0
product[0][total]    700

Can anyone help me.?

Thanks in advance..

  • 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-12T03:28:01+00:00Added an answer on June 12, 2026 at 3:28 am

    In your first version, you are assigning an array to array so, It is displaying as 2d array. and in you second version you are always assigning your product variable to new value, so it is containing only one product information. So you can update your first version by removing [ and ] like

    for(var i=1; i <= rowCount-1; i++)
    {
        product[i-1] = {
            'product_id' : $('#product_id' + i).val(),
            'name' : $('#item' + i).val(),
            'model' : $('#model' + i).val(),
            'reward' : $('#reward' +i).val(),
            'subtract' : $('#subtract' + i).val(),
            'minimum' : $('#minimum' + i).val(),
            'shipping' : $('#shipping' + i).val(),
            'tax_class_id' : $('#tax_class_id' + i).val(),
            'weight' : $('#weight' + i).val(),
            'quantity' : $('table.order-table tbody tr td.quantity input[name=\'quantity'+ i +'\']').val(),
            'price' : $('table.order-table tbody tr[id=\''+ i +'\']').find('td.price').html(),
            'total' : $('table.order-table tbody tr td.quantity input[name=\'quantity'+ i +'\']').parent().parent().find('td.total').html()
        };
    }
    

    or you can modify your second version as

    for(var i=1; i <= rowCount-1; i++)
    {  
        product.push({
            'product_id' : $('#product_id' + i).val(),
            'name' : $('#item' + i).val(),
            'model' : $('#model' + i).val(),
            'reward' : $('#reward' +i).val(),
            'subtract' : $('#subtract' + i).val(),
            'minimum' : $('#minimum' + i).val(),
            'shipping' : $('#shipping' + i).val(),
            'tax_class_id' : $('#tax_class_id' + i).val(),
            'weight' : $('#weight' + i).val(),
            'quantity' : $('table.order-table tbody tr td.quantity input[name=\'quantity'+ i +'\']').val(),
            'price' : $('table.order-table tbody tr[id=\''+ i +'\']').find('td.price').html(),
            'total' : $('table.order-table tbody tr td.quantity input[name=\'quantity'+ i +'\']').parent().parent().find('td.total').html()
        });
    }
    

    Hope It will help.

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

Sidebar

Related Questions

I'm having trouble making this work: $(function() { $(.button).click(function() { var newentry = $(input#entry).val();
I'm having trouble with this simple scenario. First, I'm using ASP.NET WebForms. I'm making
I'm having trouble making php usort work. I fetch this from DB: Array (
I'm having trouble with the way I designed this little report I'm making. Is
I'm having trouble making this simple thing happen. I have this loop adding values
I am having trouble making this work and am looking for some help. Currently
Having Trouble making sql connection. this is my code private static SqlConnection GetConnection() {
First time making a PHP/XML shopping cart and am having trouble with the update
First off this is for homework or... project. I'm having trouble understanding the idea
Im having trouble making my table contents vertically aligned and was wondering if you

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.