Elegant way to add and set property by condition in Javascript
<p>I am creating data object to send with Ajax to the server. I find myself repeating these lines to add properties to data object:</p>

<pre><code>var param1, param2;
if (param1 = $("field1").val())
  data.param1 = param1;

if (param2 = $("field2").val())
  data.param2 = param2;

etc.
</code></pre>

<p>I am just curious if there's any more elegant way to fill data object in my case? Thanks.</p>
