I have the following table saved in a variable
var table = '<table>
<tr><td>Test1</td><td>Test2</td></tr>
<tr><td>Test3</td><td>Test4</td></tr>
</table>';
Is there a possibility of doing an iteration for every tr and saving the td with JS?
I have the following table saved in a variable
var table = '<table>
<tr><td>Test1</td><td>Test2</td></tr>
<tr><td>Test3</td><td>Test4</td></tr>
</table>';
Is there a possibility of doing an iteration for every tr and saving the td with JS?
You could get it like this:
jQuery
withhtml
the variable ( eg:$(table)
)..find('td')
to get all thetd
..map(fn)
to get from eachtd
, for example, the text..get()
to get an array with the result.In this way you go through the
tr
you can save it
JS
as best suits you.If what you need is a simple
array
withtd
:This stores the content of each
td
in the arraytemp
.