Chris Burgin:
Alexandr Cherednichenko

… I’ve also added some stupidity resistance ).

Also, maybe it’s better to do it as following:

const arrayToObject = (arr = [], key) => arr.reduce((res, item, i) => ({ ...res, [key ? item[key]: i]: item }), {});

Though it’s not quite useful… 8)

And It’s not necessary, of course.

Alternative option would be checking arguments and throw appropriate exceptions.