I was able to transform two arrays into a key-value pair object.
firstArray: [] = ['a','b','c','d']
secondArray: [] = [1,2,3,4]
Below is the code used to accomplish this transformation:
let dict = firstArray.map(function(obj, index) {
let mydict = {}
mydict[secondArray[index]] = obj;
return mydict;
});
console.log(dict)
Output:
[{
"1": "a"
}, {
"2": "b"
}, {
"3": "c"
}, {
"4": "d"
}]
The expected output from this transformation is as follows:
[{
value: "1", name: "a"
}, {
value: "2", name: "b"
}, {
value: "3",name: "c"
}, {
value: "4", name:"d"
}]
If anyone can provide guidance on how to achieve this desired output, it would be greatly appreciated.