Convert object array to hash map, indexed by an attribute value of the Object
Use Case The use case is to convert an array of objects into a hash map based on string or function provided to evaluate and use as the key in the hash map and value as an object itself. A common case of using this is converting an array of objects into a hash map of objects. Code The following is a small snippet in JavaScript to convert an array of objects to a hash map, indexed by the attribute value of object. You can provide a function to evaluate the key of hash map dynamically (run time). function isFunction(func) { return Object.prototype.toString.call(func) === '[object Function]'; } /
0 upvotes
View original discussion ↗
Comments
Sign in or sign up to comment and upvote.
No comments yet.