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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:42:25+00:00 2026-05-25T10:42:25+00:00

I am iterating over an table to pick out the form elements from each

  • 0

I am iterating over an table to pick out the form elements from each table row. What am I doing wrong in the below example?

var result = new Array();
var counter = 1;

$('tbody tr', this.el).each(function(){

    var inner = new Array();

    $('input',this).each(function(){
        console.log(this.name, $(this).val());  // Works: sends name/value to console!
        inner[this.name] = $(this).val(); // Appears to be empty
    });

    result[counter] = inner;
    counter++;
});

console.log(result);
  • 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-25T10:42:25+00:00Added an answer on May 25, 2026 at 10:42 am

    You’re doing arrays wrong.

    In Javascript, an Array is a special case of object which has numeric keys only and has an interface defined by functions like push:

    var myArray = [];
    myArray.push("first element");
    myArray.push("second element");
    myArray.push("third element");
    

    You’re making the very common mistake of trying to use an array like a more generic object, assigning string keys and using x[y] = z notation in order to do so. It’s a hack that sometimes may happen to seem to work, but is not how arrays are supposed to be used.

    You have the same problem with inner and with result.

    Instead, use the generic object that you were attempting to use in the first place:

    var result  = {};     // <!-- create new _object_
    var counter = 1;
    
    $('tbody tr', this.el).each(function() {
    
        var inner = {};   // <!-- create new _object_
    
        $('input', this).each(function() {
            var val = this.value;
    
            console.log(this.name, val);
            inner[this.name] = val;
        });
    
        result[counter] = inner;
        counter++;
    });
    
    console.log(result);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When iterating over elements of a vector it is preferred to use iterators instead
If I am iterating over each file using : @echo off FOR %%f IN
I am iterating over a list and I want to print out the index
I'm trying to update a table on several remote servers by iterating over a
I'm iterating over a vector, for each element I look something up in a
Terr! HTML::Table has pretty good flexibility to form HTML-tables from perl data structures, but
I have the below table in a .JSP page: <form:form method=post action=update.dtt id=contactForms modelAttribute=contactForms
How to iterate over pairs of table elements in lua? I would like to
I'm iterating over a JRE Collection which enforces the fail-fast iterator concept, and thus
What is the correct way of iterating over a vector in C++? Consider these

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.