Hello developers Im trying to map the key value i have in an array of objects , into other array of minor length, but due to the task i have been committed is necessary to do it in this way.
Lets say i Have an array of objects of length 2 with this structure:
const array1=[
{ status: "ok", actual: true },
{ status: "not ok" },
]
And the array i pretend to add to this one has a bigger length and look like this:
const iconsStepper = [
{ icon: 'x' },
{ icon: 'xx' },
{ icon: 'xxx' }
];
Then the expected result , having in mind i need to couple the second array into the first would be :
[
{ status: "ok", actual: true ,icon:x},
{ status: "not ok",icon:xx },
{icon:xxx },
]
I got a function mapping the second array into the first:
array1.map((object, index) => ({
...object,
icon: iconsStepper[index].icon,
}));
and following this logic the result thrown is :
[
{ status: "ok", actual: true ,icon:x},
{ status: "not ok",icon:xx },
]
Being omitted the last object of the iconSteeper array cause the length of the array it supposed should be mapped to is minor
How can i fix this problem without precisely invert the array to map. Thanks