try this...function swap(o,A,B)
{
    var C = o[A];
    o[A] = o[B];
    o[B] = C;
}
swap(a,0,1)

解决方案 »

  1.   

    给数组定义一个新方法
    <script>
    /** 数组元素交换 **/
    Array.prototype.swpa = function(a,b) {
      var c = this[a];
      this[a] = this[b];
      this[b] = c;
    }
    // 例
    ar = new Array(1,2);
    alert("原数组:"+ar);
    ar.swpa(0,1);
    alert("交换后:"+ar);</script>
      

  2.   

    哈,這招高!
    順問一下,在javascript裡給系統物件擴充方法就是往prototype裡加屬性及方法嗎?
    這個屬性好像好少有人用啊!