2011-07-20 95 views

回答

1

試試這個。

var items = []; 
for(var i = 0; i < array.length; i++){ 
    items.push(array[i][1]); 
} 
+0

謝謝!非常簡單和乾淨! – takz

0

通過創建一個新的數組?

<script> 
    array = new Array(); 
    array[0] = ["2011-07-18", "373.800"]; 
    array[1] = ["2011-07-19", "372.300"]; 

    array2 = new Array(); 
    array2[0] = [array[0][1], array[1][1]]; 

    alert(array2[0]); 
</script> 
0

在新的瀏覽器(我指的Chrome/Firefox 3以上),你可以很容易地通過Array.map https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/array/map實現這一目標。您可以參考兼容性部分來自己實現Array.map以實現較舊的瀏覽器兼容性。

if (!Array.prototype.map) 
{ 
    Array.prototype.map = function(fun /*, thisp */) 
    { 
    "use strict"; 

    if (this === void 0 || this === null) 
     throw new TypeError(); 

    var t = Object(this); 
    var len = t.length >>> 0; 
    if (typeof fun !== "function") 
     throw new TypeError(); 

    var res = new Array(len); 
    var thisp = arguments[1]; 
    for (var i = 0; i < len; i++) 
    { 
     if (i in t) 
     res[i] = fun.call(thisp, t[i], i, t); 
    } 

    return res; 
    }; 
} 

var array = []; 
array[0] = ["2011-07-18", "373.800"]; 
array[1] = ["2011-07-19", "372.300"]; 
var result = array.map(function(ary) { 
    return ary[1]; 
}); 
alert(result);