I have two arrays and I want to store them in an array and create them as an object.
const name = ["Amy", "Robert", "Sofie"]; const age = ["21", "28", "25"];
The output I want is:
const person =[{name: 'Amy', age: '21'}, {name: 'Robert', age: '28'}, {name: 'Sofie', age: '25'}];
Is there a way to loop through it to make it like this, since my array is quite long and entering it manually would be cumbersome. Thanks.
Since the length of the two arrays is the same, it can be achieved using the
map
function.You can use Array.map like this: