I have two arrays: newParamArr
and paramVal
.
Example values in the newParamArr
array: [ "Name", "Age", "Email" ]
.
Example values in the paramVal
array: [ "Jon", 15, "jon@gmail.com" ]
.
I need to create a JavaScript object that places all of the items in the array in the same object. For example { [newParamArr[0]]: paramVal[0], [newParamArr[1]]: paramVal[1], ... }
.
In this case, the result should be { Name: "Jon", "Age": 15, "Email": "jon@gmail.com" }
.
The lengths of the two arrays are always the same, but the length of arrays can increase or decrease. That means newParamArr.length === paramVal.length
will always hold.
None of the below posts could help to answer my question:
Javascript Recursion for creating a JSON object
Recursively looping through an object to build a property list