I have some code like this:
$('input:checkbox:checked').each(function (index) {
indexArray.push($(this).attr("data-invoiceid"));
});
var postData = { values: indexArray.join(',') };
As you can see I’m trying to get all the invoiceids for checkboxes checked add them to the values attribute of post data as a comma delimited string. Values could get set to “1,2,5”.
So this works finds. I’m wondering if there is a better way of doing this where the step of adding the values to the array first could be removed?
You could also use map. Although it still uses an array, it is cleaner and follows a function approach.