How can I merge two arrays of Objects that have different keys pairs. I would be OK to use a library or ES6 features.
const listOfQuestions = [{
question1: {
important: true
}
}, {
question2: {
important: false
}
}]
const listOfAnswers = [{
question1: {
answer: false
}
}, {
question2: {
answer: true
}
}]
Expected result:
const result = [{
"question1": {
"important": true,
"answer": false
}
}, {
"question2": {
"important": false,
"answer": true
}
}]
I tried to use spread syntax:
const test = [...listOfQuestions, ...listOfAnswers]
But then I get something very out of what I needed:
[
{
"question1": {
"important": true
}
}, {
"question2": {
"important": false
}
}, {
"question1": {
"answer": false
}
}, {
"question2": {
"answer": true
}
}
]