私は唯一の違いは、オブジェクトの私の配列は、2つの以上の要素を持っていることであるhereグループの配列項目は、私は2つの以上の要素
解決しようとしている問題の種類については、この解決策を見つけた となります結果は望んでいた誰かしてくださいできソリューションに似ていますが、すべての要素
{
"group": "one",
"color": ["red", "green", "black"],
"size": ["big"],
"date": ["11/08/2018"]
}
でだから私はすべての私の値を表示するために取得する.map()
を繰り返してきたが、私は、私はいけないと感じて...
より簡単でより良いオプションで私を助けてください?後で追加されたコードについて
var db = [{"Record":{"id":"26","cost_center":"15073 DC1 M8 - Filmatic","batch_no":"367746","item_code":"12583","description":"LF Fruited Guava (2x6)x15"}},{"Record":{"id":"29","cost_center":"15073 DC1 M8 - Filmatic","batch_no":"367749","item_code":"12583","description":"LF Fruited Guava (2x6)x15"}},{"Record":{"id":"36","cost_center":"15093 DC1 M10 - CornerPot Machi","batch_no":"367756","item_code":"12256","description":"PROMO CP LF SaltedCar w H"}}];
var myArray = [];
for (var i in db) {
if (db.hasOwnProperty(i)) {
myArray.push(db[i].Record);
}
}
var res = myArray.reduce(function(res, elem) {
if (res.indexOf(elem.cost_center) === -1) {
res.push(elem.cost_center);
}
return res;
}, []).map(function(machine) {
return {
cost_center: machine,
batch_no: myArray.filter(function(_el) {
return _el.cost_center === machine;
}).map(function(_el) { return _el.batch_no; }),
item_code: myArray.filter(function(_el) {
return _el.cost_center === machine;
}).map(function(_el) { return _el.item_code; }),
description: myArray.filter(function(_el) {
return _el.cost_center === machine;
}).map(function(_el) { return _el.description; })
}
});
console.log(res);
どこから 'size'と' date'、などの追加のプロパティを取得できますか? –
お客様から@NinaScholz – Jonathan
okですが、データ構造はありますか? –