I am building a querystring and want to exclude keys if vals are empty, what’s a proper way?
setQueryString: function () {
var keyword = $('#keyword').val();
//how to exclude it if keyword is empty?
var params = {
"keyword": $.trim(keyword)
};
return params;
}
take into account, that I will have 20+ inputs like keyword..trying to avoid lots of IF statements
Don’t set it if it’s empty is all:
(edit)
If you have lots of things to check, consider using either a loop:
or a function of some kind, for example: