How can we read input value into an array for all td array = [1,2,3].using pure javascript
I tried this but it creates an array of objects, but I just want to store only values in an array. Can anyone tell how it can be accomplished?
const array = [...document.querySelectorAll("table tbody tr")].map((row) => {
const [id] = [...row.querySelectorAll('td')].map(td => td.textContent.trim());
return { id }
})
console.log(array);
<table>
<tbody>
<tr>
<td>Smith</td>
<td>
<button onclick="removeName(this);">Remove</button>
<input type="hidden" value="1" name="id" />
</td>
</tr>
<tr>
<td>Smith</td>
<td>
<button onclick="removeName(this);">Remove</button>
<input type="hidden" value="2" name="id" />
</td>
</tr>
<tr>
<td>Smith</td>
<td>
<button onclick="removeName(this);">Remove</button>
<input type="hidden" value="3" name="id" />
</td>
</tr>
</tbody>
</table>
Idtoidvalueof eachinputinside of thetds? So[1, 2, 3]. Your title is confusing since you're asking to gettdvalues, buttds don't have values