我有數據,看起來像這樣:提取散列陣列的幾個陣列,縮短代碼
[{label: "uno", men: 3, kids: 2, womens: 5}, {label: "dos", men: 4, kids: 2, womens: 2}]
在轉化結束時,我想有4個陣列包含數據字段:
var labels = ["uno", "dos"];
var men = [3, 4];
var kids = [2, 2];
var womens = [5, 2];
我做這樣的:
var label = [];
var men = [];
var kids = [];
var women = [];
dataArray.forEach(function(data){
label.push(data.label);
men.push(data.men);
kids.push(data.kids);
women.push(data.women);
});
是否有一個更好/更短的方式來達到同樣的數據轉換?非常感謝!
你的代碼的結果是相當最佳 – Satpal
僅供參考,在JS中,所有對象都是哈希值。稱他們爲數組,而不是哈希。 – evolutionxbox