const idArray = [3, 5, 6];
const nameArray = ['Dima', 'Oleg', 'Vova', 'Kate' ];
const newArray = [
{name: 'Dima', id: 3},
{name: 'Oleg', id: 5},
{name: 'Vova', id: 6},
{name: 'Kate'},
{name: 'Vita'}
]
function combine(keys, values) {
const length = Math.max(0, ...values.map(n => n.length));
const arr = Array.from({ length }, () => ({}));
values.forEach((n, i) => n.forEach((m, j) => arr[j][keys[i]] = m));
return arr;
}
const newArray = combine([ 'name', 'id' ], [ nameArray, idArray ]);