1const names = ['Alex', 'Bob', 'Johny', 'Atta'];
2
3// convert array to th object
4const obj = Object.assign({}, names);
5
6// print object
7console.log(obj);
8
9// {0: "Alex", 1: "Bob", 2: "Johny", 3: "Atta"}
10
1[
2 { id: 10, color: "red" },
3 { id: 20, color: "blue" },
4 { id: 30, color: "green" }
5].reduce((acc, cur) => ({ ...acc, [cur.color]: cur.id }), {})
6
7//output:
8{red: 10, blue: 20, green: 30}