how to use if condition in jQuery foreach loop
<p>i have a json string with some detail and i want to get value from json string according to if condition but there is something wrong that i am not getting value.<br/>
what is i want do there is two car type <strong>4Seater</strong> and <strong>8Seater</strong> in dropdown when i change car type then i want to all cars name from json string in option on the next dropdown that is cars. i have tried below code but is not showing any option. i have no idea what to do.</p>

<pre><code>&lt;script src="jquery-1.12.0.js"&gt;&lt;/script&gt;
&lt;body&gt;
    &lt;select id="capacity"&gt;
        &lt;option value=""&gt;Select&lt;/option&gt;
        &lt;option value="4Seater"&gt;4Seater&lt;/option&gt;
        &lt;option value="8Seater"&gt;8Seater&lt;/option&gt;
    &lt;/select&gt;
    &lt;select id="cars"&gt;&lt;/select&gt;
    &lt;script type="text/javascript"&gt;
        $(document).ready(function(){
            var jsonstirn = '[{"capacity":"4Seater","carname":"car1","price":"83"},{"capacity":"4Seater","car2":"i10","price":"83"},{"capacity":"8Seater","carname":"car3","price":"83"}]';
            var jsonarray = JSON.parse(jsonstirn);

            $('#capacity').change(function(){
                var cars = ''
                var capacityval = $('#capacity').val();
                $.each(jsonarray,function(i,item){
                    if(item.capacity == capacityval){
                        cars+='&lt;option value="'+item.carname+'"&gt;'+item.carname+'&lt;/option&gt;';
                    };
                });
                $('#cars').html(cars);
            });
        });
    &lt;/script&gt;
&lt;/body&gt;
</code></pre>