Seeking a swift javascript solution to merge two arrays with the same length into an array of json objects. In addition, the code should append any errors to the existing .error element. Preferably, the solution should utilize vanilla javascript instead of ES6.
var codes = ["12345", "12345","67890", "67890", "67890","67890","12092", "12092"];
var errors = ["12345 error 1","12345 error 2","67890 error 1","67890 error 2","67890 error 3","67890 error 4","12092 error 1","12092 error 2"];
Desired transformation:
{
"code": "12345",
"error": "12345 error 1, 12345 error 2"
},
{
"code": "67890",
"error": "67890 error 1, 67890 error 2, 67890 error 3, 67890 error 4, 67890 error 5"
},
{
"code": "12092",
"error": "12092 error 1 , 12092 error 2"
}