[
{
VendorCode: 'kek',
Color: 'Черный',
Size: '35'
},
{
VendorCode: 'kek',
Color: 'Черный',
Size: '36'
},
{
VendorCode: 'kek',
Color: 'Белый',
Size: '35'
}
]
[
{
Name: 'Белый',
Hex: '#FFF'
},
{
Name: 'Черный',
Hex: '#000'
}
]
[
'#FFF',
'#000'
const a = [
{
VendorCode: 'kek',
Color: 'Черный',
Size: '35'
},
{
VendorCode: 'kek',
Color: 'Черный',
Size: '36'
},
{
VendorCode: 'kek',
Color: 'Белый',
Size: '35'
}
]
const b = [
{
Name: 'Белый',
Hex: '#FFF'
},
{
Name: 'Черный',
Hex: '#000'
}
]
function unique(arr) {
let res = [];
for (let el of arr) {
if (!res.find(rl => rl.Color === el.Color)) {
res.push(el);
}
}
return res;
}
const c = unique(a).map(el => b.find(elb => elb.Name === el.Color)?.Hex)
const arr1 = [{
VendorCode: 'kek',
Color: 'Черный',
Size: '35'
},
{
VendorCode: 'kek',
Color: 'Черный',
Size: '36'
},
{
VendorCode: 'kek',
Color: 'Белый',
Size: '35'
}
]
const arr2 = [{
Name: 'Белый',
Hex: '#FFF'
},
{
Name: 'Черный',
Hex: '#000'
}
]
// ------------------------------
const result = arr2.reduce((acc, value2) => {
if (arr1.find((value1) => value1.Name === value2.Color)) {
acc.push(value2.Hex);
}
return acc;
}, []);
// or
const result2 = arr2.reduce((acc, value2) => (arr1.find((value1) => value1.Name === value2.Color) && acc.push(value2.Hex), acc), []);