Why couldn't i insert the same element into an array in javascript?
<p>I have a array of objects. But when I insert the object the I previously added, it will override my previous object. how can I solve it?</p>

<p>I have on object called player. In player, I have two array : one called onHandWeapon, one called onFieldWeapon. They are array of weapon object.</p>

<pre><code>function player(lp){
        this.lp = lp;
        this.onFieldWeapon = new Array();
        this.onHandWeapon = new Array();

    } 

function weapon(id, heart, bullet, src){
            this.id = id;
            this.heart = heart;
            this.bullet = bullet;
            this.src = src;
            this.location;
            this.name;
            this.discription;
            this.bufferBullet = bullet;
    }
</code></pre>

<p>I have set three dummy object in onHandWeapon array. Then I want to randomly pick up one of them and put it into onFieldWeapon and assign a random location to it. </p>

<pre><code> function aiCreateWeapon(){
        var b = Math.floor(Math.random()*ai.onHandWeapon.length);
        $('#console').append(' ' + b + ' ');
        var ip = 100;

        while($('#'+ip).attr('class') != 'enemyField'){
            ip = Math.floor(Math.random()*48);
        }

        encurrentWeapon = ai.onHandWeapon[b];

        var source = encurrentWeapon.src;

        var oImg = document.createElement("img");
        oImg.setAttribute('src', source);
        oImg.setAttribute('height', '60px');
        oImg.setAttribute('width', '60px');
        $('#'+ip).append(oImg).show('explode','slow');

        encurrentWeapon.location = ip;  
        ai.onFieldWeapon.push( encurrentWeapon);

        $('#console').append(' ' + ai.onFieldWeapon[0].location + ' ');
}
</code></pre>

<p>aiCreateWeapon is a function bind to a button. When I click it, the ai.onFieldWeapon[0].location is a fixed location until it changes. I have check that every time when the object which is same as the first element, is added to the onFieldWeapon Array, it will override the first element's data. </p>
