Could this string splitter be refactored or improved?
<p>The following code snippet does the following:</p>

<p>Given a string like:  <code>"key1=value1;key2=value2;key3=value3"</code>, it will perform a lookup for key1 and set the value to value1 using jQuery:  </p>

<pre><code>$("#key1").val("value1");
</code></pre>

<p>My goal was to not assume the string is in the right format, so it might not have a <code>;</code>, or it might not have a <code>=</code>.  So the code should guard itself from crashing.</p>

<p>How could this be improved using the correct javascript style/idioms:</p>

<pre><code>var myString = "key1=value1&amp;key2=value2;key3=value3";
var kvp = myString.split(";");
if (kvp &amp;&amp; kvp.length) {
    for (var x = 0; x &lt; kvp.length; x++) {
        var parts = kvp[x];
        if (parts &amp;&amp; parts.length &amp;&amp; parts.indexOf("=") &gt;= 0) {
           var kv = parts.split("=");
           $("#" + kv[0]).val(kv[1]);
        }
    }
}
</code></pre>
