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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:22:11+00:00 2026-06-15T06:22:11+00:00

I need to store table cell content into array using tr and td indexes

  • 0

I need to store table cell content into array using tr and td indexes like this:

myArray[tr_idx][td_idx]='value';

It is not required to store data of all of cells in array but only several with a special content, but if i use indexes as a keys of the array i’ll have many empty array elements.

e.g.

myArray[2][3]='data1';
myArray[4][3]='data2';

alert (myArray.toSource()) -> [, , [, , , "data1"], , [, , , "data2"]]

maybe there is another suitable way of storing such type of data?

  • 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-15T06:22:12+00:00Added an answer on June 15, 2026 at 6:22 am

    Why not just store them as individual 2-item arrays [row,col]? Since the table cells are already accessible via tableElement.rows[].cells[], you can use the 2 indices to access them from the table.

    var storedCells = [];
    // Store row 2, column 3
    storedCells.push([2,3]);
    

    Access with:

    // Table row:
    storedCells[0][0]
    // Table column
    storedCells[0][1]
    
    //As in :
    tableElement.rows[storedCells[0][0]].cells[storedCells[0][1]].innerHTML = "New cell value!"
    

    Or even cleaner, if you prefer to use objects rather than arrays:

    storedCells.push({row: 2, column: 3});
    storedCells.push({row: 4, column: 6});
    

    Accessed with:

    tableElement.rows[storedCells[0].row].cells[storedCells[0].column].innerHTML = "New cell value!";
    

    Finally, if you don’t actually need the row/column indexes, but rather the DOM nodes themselves, just push those onto your array.

    var storedCells = [];
    // Save references to some individual <td> nodes
    storedCells.push(tableElement.rows[1].cells[2]);
    storedCells.push(tableElement.rows[4].cells[6]);
    

    They are then trivially modified:

    // Set the value of the second element:
    storedCells[1].innerHTML = "New content!";
    

    Update after comment:

    If you need to be able to attach the cell coordinates to a new value from the backend, a good solution would be to expand the object {} example above to include a value attribute. The server can pass back the new value in JSON.

    storedCells.push({row: 2, column: 3, value: ""});
    storedCells.push({row: 4, column: 6, value: ""});
    

    Your backend should send a JSON response back to the script containing the same type of array of objects, where value: has been populated with the new cell value. You can then pass it back into the table with:

    // Pass the value attribute received from JSON into the cell's contents
    tableElement.rows[storedCells[0].row].cells[storedCells[0].column].innerHTML = storedCells[0].value;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to store in a MySQL database table ASCII character codes like this
I need to store different table markup code in a php array, as a
If I create ImageButton dynamically and add this into table cell TableRow tr =
When I store into table the id of any tweet like 'tweet->id', its also
Ok, I need to store/retrieve a bit from a data table of 3.268.760 bits
need help in error in database pivot. i have table tamed table_score like below:
I need a table that stores key-value pairs, so I created one with a
I have a table like this: | X | Y | Data | ----------------
I need to store a lookup table as an instance member in one of
I need to store a large table (several millions or rows) that contains a

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.