How to Exclude Input by Name Before Serialize in jQuery

I have seen a couple of answers online for how to include all inputs except one with a specific name using jQuery such as this one:

 

let params = $('input[name!=csrfmiddlewaretoken]', form).serialize();

 

This isn't particularly useful, however, since you will probably have fields other than input in your form such as select and textarea.

 

A better solution is to only target an input with a specific name and keep everything else. This can be done using the :not selector like this:

 

let params = form.find(':not(input[name=csrfmiddlewaretoken])').serialize();
jquery