I have this array:
let checks = document.querySelectorAll("#tableEvents input[type='checkbox']");
checks.forEach(e => {
console.log(e.checked);
});
checks is then an array of inputs, and the console shows the expected output, i.e.:
true
false
false
true
My goal is to join these values: true,false,false,true.
I tried this solution:
let values = checks.map(item => item.checked);
let joined = values.join();
but it returned:
Uncaught TypeError: checks.map is not a function
Of course, I can just build up the string by myself:
let s = "";
checks.forEach(e => { s += e.checked + ","; })
s.slice(0, -1)
but I'm trying to learn a more elegant way, if it exists.
querySelectorAllreturns.querySelectorAllisn't an array, even if it looks alike. It is instead aNodeList, but you can convert it to array usingArray.from(...)[...checks].join(' ')should probably work as well.