My task was to convert array to object using loops.
arr = ['a', 'b', 'c', 'd', 'e'];
to object array
arr = {'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5};
I got the right result, but I am not sure about the way I was solving this task. Please give me a piece of advice.
let arr = ['a', 'b', 'c', 'd', 'e'];
let obj = {};
for (let i = 0; i < arr.length; i++) {
obj[arr[i]] = i + 1
}
console.log(obj)
As I mentioned before, the result is right
{ a: 1, b: 2, c: 3, d: 4, e: 5 }
But I tend to feel that there is a better solution.