Select ids from jquery element array

In the following jquery expression, I select an array of elements:

selectedSupplierIds = $('.supplierListCheckbox:checked');

I need to select identifiers from these elements. Can I do this without creating an array and pushing identifiers in a for loop?

+3
source share
1 answer

You can use .map()to get an array of something based on the choice of an object ... in this case, you just need to get .idfrom each, for example:

var arr = $('.supplierListCheckbox:checked').map(function() { 
            return this.id; 
          }).get();
+6
source

Source: https://habr.com/ru/post/1777901/


All Articles