JavaScript: From array to object

Last update: 16 Oct 23:20
1
Student
100%
Completion rate

fromPairs.js

Implement and export as default a function that takes an array of array-pairs and returns an object derived from those pairs.

Tips

  • If same keys are found when constructing an object, take the value from the last array-pair:
fromPairs([['cat', 5], ['dog', 6], ['cat', 11]])
// { 'cat': 11, 'dog': 6 }

Examples

fromPairs([['fred', 30], ['barney', 40]]);
// { 'fred': 30, 'barney': 40 }

For full access to the challenge you need a professional subscription.

A professional subscription will give you full access to all Hexlet courses, projects and lifetime access to the theory of lessons learned. You can cancel your subscription at any time.

Get access
130
courses
1000
exercises
2000+
hours of theory
3200
tests