What’s the best method for looping through a table, grabbing all the data in the cells, but skipping the <th>? Do I put the data in an array?
What’s the best method for looping through a table, grabbing all the data in
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
Say you have a table that looks like this:
You could do something like this:
What exactly are you looking to do with the data?
The easiest thing to do to skip the headers would to just remove them from the array after the loop is done.
After the code is done, you can run something like this:
cells = cells.slice(1, cells.length);
This will set the array to a copy of itself, minus the first element.
Alternatively, when you initially loop through it, only store the information if the index is greater than zero:
And finally, if you’d like to go with a more traditional javascript solution that does not require a condition:
That way, you’re starting from the second row.