Q:

Is this a bug in javascript? The method push of Array object

This is the example code.
window.onload = function() {
    var i, arr = [], result = [];

    arr.push(1);
    arr.push(2);
    arr.push(3);

    for ( i = 0; i < 20; i++ ) {
        arr.push(5);
        arr.push(6);

        result.push(arr);
        arr.length = 3;
    }

    console.log(result);
}

Output:
 Array[20] 

 0: Array[3] 

 1: Array[3] 

 2: Array[3]

 etc...

A:

Your array of arrays contains a reference to an array which you set the length of to 3. This is exactly the result you should get. Link to ECMA 5.1.

