Creating a dictionary Object from an Array
Problem
You have an Array of Objects, such as:
But you want to access it as a dictionary by key, like cats["Bubbles"]
.
Solution
You need to convert your array into an Object. Use reduce for this.
To use this:
Discussion
Alternatively, you can use an Array comprehension:
If you use Underscore.js, you can create a mixin: