I have a table of data that I want to grab text from, stick into an array (and then use with Google maps).
The table looks like:
<table>
<thead>
<tr>
<th>One</th>
<th>Two</th>
</tr>
</thead>
<tr class='bar'>
<td class='name'>Bob</td>
<td class='number'>12345</td>
</tr>
<tr class='bar'>
<td class='name'>Jane</td>
<td class='number'>-55.34</td>
</tr>
</table>
I want to grab the text from the table cells and build an array of it all. Something like:
var foo = [
['Bob', 12345],
['Jane', -55.34]
]
What I tried, using jquery, was:
var foo = [];
$('.bar').each(function(){
foo.push($('.name').text(), $('.number').text());
});
But that, obviously, does not work giving (and I'm pretty sure I'm just using the selector the wrong way):
["BobJane", 12345-55.34]
So how do you get the contents from each TD within each TR and build the array with it so I get the desired above example (with each set of data in it's own row)?