I have two arrays, one with names and another with id's that relate to the names.
arr1 = ["Bob Jones", "Steven Simon", "Green Tea"];
arr2 = [10, 8, 13];
The Id's in arr2 correspond to the names in arr1. For example, Bob Jones has an Id of 10. What I would like to do is return a single array of objects as follows:
[
{
Id: 10,
Name: Bob Jones
},
{
Id: 8,
Name: Steven Simon
},
{
Id: 13,
Name: Green Tea
}
]
I have attempted to use Object.defineproperties as per the code below.
const myOjbect = {};
Object.defineProperties(myObject, {
name: {
value: arr1[0],
enumerable: true,
writable: false,
},
id: {
value: arr2[0],
enumerable: true,
writable: true,
},
})
This provides the expected result for first item in the array but I also need the subsequent items in the array to be included in the object (not just the first one).