Neznajka,
let arrayMain = [
{
order: 234,
Dat: '23-11',
firma: 156,
director: 45,
zakaz: [
{ produkt: 34, sum: 5 },
{ produkt: 17, sum: 1 },
{ produkt: 24, sum: 3 },
{ produkt: 19, sum: 5 }
]
},
{
order: 235,
Dat: '24-11',
firma: 368,
director: 12,
zakaz: [
{ produkt: 17, sum: 2 },
{ produkt: 24, sum: 4 },
{ produkt: 34, sum: 2 }
]
},
{
order: 236,
Dat: '25-11',
firma: 213,
director: 96,
zakaz: [
{ produkt: 24, sum: 7 },
{ produkt: 34, sum: 2 }
]
}
];
let slovarFirm = [
{ kod: 156, name: 'Ямал-сервис' },
{ kod: 213, name: 'Рассвет' },
{ kod: 368, name: 'ЭлектроСила' }
];
let slovarPers = [
{ kod: 12, name: 'Иванов' },
{ kod: 45, name: 'Петров' },
{ kod: 96, name: 'Сидоров' }
];
let slovarProd = [
{ kod: 17, name: 'Бумага' },
{ kod: 19, name: 'Маркеры' },
{ kod: 24, name: 'Скрепки' },
{ kod: 34, name: 'Карандаши' }
];
const createObj = (arr) =>
arr.reduce(function (obj, el) {
obj[el.kod] = el.name;
return obj;
}, {});
slovarFirm = createObj(slovarFirm);
slovarPers = createObj(slovarPers);
slovarProd = createObj(slovarProd);
arrayMain = arrayMain.map(function (ob) {
ob.firma = slovarFirm[ob.firma];
ob.director = slovarPers[ob.director];
ob.zakaz.forEach(function (el) {
el.produkt = slovarProd[el.produkt];
});
return ob;
});
console.log(arrayMain);