-2
私はjsonを初めて使用しています。JSONオブジェクトフィルタ
私は以下のとおりです。
var data =[
{
"year":2015,
"month":1,
"total_sales":123
},
{
"year":2015,
"month":2,
"total_sales":212
},
{
"year":2015,
"month":3,
"total_sales":602
},
{
"year":2015,
"month":4,
"total_sales":918
},
{
"year":2015,
"month":5,
"total_sales":920
},
{
"year":2015,
"month":6,
"total_sales":167
},
{
"year":2015,
"month":7,
"total_sales":922
},
{
"year":2015,
"month":8,
"total_sales":162
},
{
"year":2015,
"month":9,
"total_sales":678
},
{
"year":2015,
"month":10,
"total_sales":312
},
{
"year":2015,
"month":11,
"total_sales":895
},
{
"year":2015,
"month":12,
"total_sales":470
},
{
"year":2016,
"month":1,
"total_sales":962
},
{
"year":2016,
"month":2,
"total_sales":501
},
{
"year":2016,
"month":3,
"total_sales":115
},
{
"year":2016,
"month":4,
"total_sales":193
},
{
"year":2016,
"month":5,
"total_sales":199
},
{
"year":2016,
"month":6,
"total_sales":169
},
{
"year":2016,
"month":7,
"total_sales":482
},
{
"year":2016,
"month":8,
"total_sales":197
},
{
"year":2016,
"month":9,
"total_sales":375
},
{
"year":2016,
"month":10,
"total_sales":497
},
{
"year":2016,
"month":11,
"total_sales":692
},
{
"year":2016,
"month":12,
"total_sales":868
},
{
"year":2017,
"month":1,
"total_sales":292
},
{
"year":2017,
"month":2,
"total_sales":602
},
{
"year":2017,
"month":3,
"total_sales":744
},
{
"year":2017,
"month":4,
"total_sales":248
},
{
"year":2017,
"month":5,
"total_sales":549
},
{
"year":2017,
"month":6,
"total_sales":694
},
{
"year":2017,
"month":7,
"total_sales":793
},
{
"year":2017,
"month":8,
"total_sales":436
},
{
"year":2017,
"month":9,
"total_sales":752
},
{
"year":2017,
"month":10,
"total_sales":852
},
{
"year":2017,
"month":11,
"total_sales":588
},
{
"year":2017,
"month":12,
"total_sales":807
}
]
そして私はそれを以下のフォーマットで縮小したいと思います。これまでに試みられてきた何
var data = [
{
"month":"january",
"2015":123,
"2016":962,
"2017":292
},
{
"month":"february",
"2015":212,
"2016":30,
"2017744 602 },{ " month":"march",
"2015":212,
"2016":30,
"2017":20
} ....
];
:事前に
var uniqueYears = [];
for (i = 0; i < data.length; i++) {
if (uniqueYears.indexOf(data[i].year) === -1) {
uniqueYears.push(data[i].year);
}
}
var uniqueMonths = [];
for (i = 0; i < data.length; i++) {
if (uniqueMonths.indexOf(data[i].month) === -1) {
uniqueMonths.push(data[i].month);
}
}
var attributelist = [];
console.log(data.length);
for (i = 0; i < data.length; i++) {
var as = $(data).filter(function(i, n) {
console.log(n) return n.month === uniqueMonths[i]
});
}
感謝。
あなたがこれまでにしようとしているものを投稿してください。 –
あなたはStackOverflowがヘルプデスクだと思いますか?スニーカーになろうとはしませんが、もしそれがあなたの考えであれば、それは –
ではありません。あなたが試したことを少しでも努力して見せてください。 – Amy