I have two arrays, and presently I am combining them into one array like so:
const changeArr = selectedReasons.map((e, i) => e + changeComments[i]);
That works, but what I'd ideally like to do is, rather than mashing them into one element, is create an array of objects, where each object has a property referencing the first array, and the second property being the corresponding index element from the second array.
So imagine the first array looks like this:
selectedReasons = [
"100A",
"100B"
]
And the second one looks like this:
changeComments = [
"Here is my clarifying comment for the first choice.",
"This is a different comment pertaining to my second choice."
]
What I'd like to end up with is this:
changeArr = [
{
reason: "100A",
comment: "Here is my clarifying comment for the first choice."
},
{
reason: "100B",
comment: "This is a different comment pertaining to my second choice."
}
]
How can I adjust my current code which mashes together elements into an array of objects with two properties for each object, that match based on the index of the elements?