✅ – dmikester1 – 19-47 Mar 14

I have 2 objects with the same keys. I want to combine the objects into a single array of objects.
questions: Object {​​
crossContamination: "Is cross contamination at an acceptable level?",
mixer6Production: "Is anything being produced in mixer 6?",
product: "What product are we producing?",
barrelsEmptiedOnPiles: "Any mixed overflow barrels emptied on piles?",
binsLabeledCorrectlyOnCatwalk: "Are bins labeled correctly on catwalk level and readable?",
binsLabeledCorrectlyOnGround: "Are bins labeled correctly on ground level and readable?",
​​comments: "Additional comments for product(s) concern or quality:",
​​crossContamination: "Is cross contamination at an acceptable level?",
foreignProducts: "What are the foreign product(s)?",
mixer6Production: "Is anything being produced in mixer 6?",
overflowBarrelsEmpty: "Are the overflow barrels empty?",
overflowInfo: "Additional information is required:",
paintFloorWetDry: "Is the plant floor wet or dry?",
product: "What product are we producing?",
​​properWeight: "Is scale set at the proper weight?",
}
​​
checkData: Object {
crossContamination: "No",
mixer6Production: "Yes",
product: "other one",​​
barrelsEmptiedOnPiles: "No",​​
binsLabeledCorrectlyOnCatwalk: "Yes",​​
binsLabeledCorrectlyOnGround: "No",​​
comments: "quality",​​
crossContamination: "No",​​
mixer6Production: "Yes",​​
overflowBarrelsEmpty: "Yes",​​
paintFloorWetDry: "Wet",​​
product: "other one",​​
properWeight: "No",
}
questions: Object {​​
crossContamination: "Is cross contamination at an acceptable level?",
mixer6Production: "Is anything being produced in mixer 6?",
product: "What product are we producing?",
barrelsEmptiedOnPiles: "Any mixed overflow barrels emptied on piles?",
binsLabeledCorrectlyOnCatwalk: "Are bins labeled correctly on catwalk level and readable?",
binsLabeledCorrectlyOnGround: "Are bins labeled correctly on ground level and readable?",
​​comments: "Additional comments for product(s) concern or quality:",
​​crossContamination: "Is cross contamination at an acceptable level?",
foreignProducts: "What are the foreign product(s)?",
mixer6Production: "Is anything being produced in mixer 6?",
overflowBarrelsEmpty: "Are the overflow barrels empty?",
overflowInfo: "Additional information is required:",
paintFloorWetDry: "Is the plant floor wet or dry?",
product: "What product are we producing?",
​​properWeight: "Is scale set at the proper weight?",
}
​​
checkData: Object {
crossContamination: "No",
mixer6Production: "Yes",
product: "other one",​​
barrelsEmptiedOnPiles: "No",​​
binsLabeledCorrectlyOnCatwalk: "Yes",​​
binsLabeledCorrectlyOnGround: "No",​​
comments: "quality",​​
crossContamination: "No",​​
mixer6Production: "Yes",​​
overflowBarrelsEmpty: "Yes",​​
paintFloorWetDry: "Wet",​​
product: "other one",​​
properWeight: "No",
}
D
dmikester1401d ago
The combined array would look like this:
[{id: "crosscontamination", question: "Is cross contamination at an acceptable level?", answer: "No"}, {id: "mixer6Production", question: "Is anything being produced in mixer 6?", answer: "Yes"}, etc]
[{id: "crosscontamination", question: "Is cross contamination at an acceptable level?", answer: "No"}, {id: "mixer6Production", question: "Is anything being produced in mixer 6?", answer: "Yes"}, etc]
V
Vanishy401d ago
are these two objects just separate variables? In that case you literally just do const array = [obj1, obj2]
D
dmikester1401d ago
They are separate variables, I'll see what that does. unfortunately, that just creates an array with the 2 objects
V
Vanishy401d ago
oh sorry, I misunderstood the question you want to iterate through the keys of the first object with Object.keys(obj1).map(key => { ... }) and inside the map you can have the logic to get questions and answers
D
dmikester1401d ago
ok, that makes sense
UU
Unknown User400d ago