const b = [
{ id: 2035, carsIds: [135, 148] },
{ id: 2036, carsIds: [136, 148] }
];
const c = [
{ carId: 135, ids: [2035] },
{ carId: 136, ids: [2036] },
{ carId: 148, ids: [2035, 2036] }
];
const d = [...new Set(b.map(({ carsIds }) => carsIds).flat())];
const e = d.map((carId) => {
const ids = b
.filter(({ carsIds }) => carsIds.includes(carId))
.map(({ id }) => id);
return {
carId,
ids
};
});