Having a cleaner syntax a prefer using map() instead of forEach()

This commit is contained in:
Jean-Baptiste Bellet
2023-02-01 10:19:04 +01:00
parent 58ea3a10e8
commit 8926a3f08d

View File

@@ -12,12 +12,9 @@ export default class extends ApplicationController {
// private
getOrdersIds() {
const order_ids = [];
document
.querySelectorAll("#listing_orders input[name='order_ids[]']:checked")
.forEach((checkbox) => {
order_ids.push(checkbox.value);
});
return order_ids;
const checkboxes = document.querySelectorAll(
"#listing_orders input[name='order_ids[]']:checked"
);
return Array.from(checkboxes).map((checkbox) => checkbox.value);
}
}