Remove item from Javascript array on change
<p>I have a bit of situation. Basically I am adding an item to JavaScript array, which I am populating on select box change. But the problem is when I input 0, it should removed from an array. </p>

<p>Here is the code </p>

<pre><code>var addon = new Array();
function updateAddons(){
    addon.length=0;

    var plan = new Array;
    var planQty = new Array;

    plan.length=0;
    planQty.length=0;

    for(var j =0 ; j&lt; 3; j++){
        $("select[name='addon_"+j+"[]'] option:selected").each(function(){
            var item = {
                product_name : $(this).attr('pn'),
                product_cost : $(this).attr('cost'),
                product_id : $(this).val()
            };
            if(item.product_id != 0){
                plan.push(item);
            }
        });
        $("input[name='addonQty_"+j+"[]'] ").each(function(){
            if($(this).val() != 0){
                planQty.push($(this).val());
            }
        });
    }

    for(var i =0; i &lt; plan.length; i++){
        var item = {
            product:plan[i],
            product_qty:planQty[i]
        }
        if(item.product.product_id != 0){
            addon.push(item);
        }

    }

}
</code></pre>

<p>I have created a jsfiddle <a href="http://jsfiddle.net/hfu5S/" rel="nofollow">click here</a> to view that. (check your browser console for the complete object.)</p>

<p>If someone can help. And please explain your answer.</p>

<p>Regards</p>
