例:mapで新しい配列作成
// 例:2項目の配列を「age」項目のみの配列に作成
var data=[
{age:24, address:"Tokyo"},
{age:24, address:"Osaka"},
{age:24, address:"Saporo"},
{age:24, address:"Okinawa"},
{age:24, address:"Saitama"},
]
var result = data.map(function(d){
return d.age ;
}) ;
console.log(result);
例:reduceで配列にある項目別の合計値
// 3項目の配列
var data=[
{number:24, time:12, items:28},
{number:14, time:23, items:34},
{number:13, time:18, items:21},
{number:18, time:15, items:24},
]
var result = data.reduce(function(a,b){
a[0] += b.number;
a[1] += b.time ;
a[2] += b.items ;
return a ;
}, [0,0,0]) ; // 新しい配列を引数「a」に渡す
console.log(result);