Based on my code I want to push each row\'s inputs to each array. If it is row1, it should push all the input values of row 1 to array a1
. The second row\'s inputs
I would do it like this :
$("#check").click(function() {
// collect data
var rows = $("tr").get().map(r => (
$("input", r).get().map(i => i.value)
));
// print data
$("#output").html("Pushed arrays:
" + rows.map((r, i) => (
"a" + (i + 1) + ": [" + r.join(", ") + "]"
)).join("
"));
});
1
2
JQuery API and MDN doc :
Demo of join
, map
and arrow functions :
xs = ["A", "B", "C"]
// ["A", "B", "C"]
"[" + xs.join(", ") + "]"
// "[A, B, C]"
xs.map(function (x) { return parseInt(x, 16); })
// [10, 11, 12]
xs.map(x => parseInt(x, 16))
// [10, 11, 12]
xs.map((x, i) => x + i)
// ["A0", "B1", "C2"]
xxs = [["A", "B"], ["C", "D"]]
// [["A", "B"], ["C", "D"]]
xxs.map(xs => "[" + xs.join(", ") + "]")
// ["[A, B]", "[C, D]"]
xxs.map(xs => "[" + xs.join(", ") + "]").join("
")
// "[A, B]
[C, D]"