Array to Hashmap in Express application
এই আমি সামায়ুন,
এই আমার ফ্রেমওয়ার্ক ( https://github.com/samayun/express-mvc-rest-boilerplate )
এবার পার্টি হবে যে 😉
ব্যক্তিগত কারণে এরে ডাটা স্ট্রাকচারে কে ডিভোর্স দিয়ে হ্যাশম্যাপ ব্যবহার করতে যাচ্ছি ।
আপনিও গাড়িসহ আমার সাথে আত্মগোপনে যেতে চলে আসুন আমার রিপোজিটরি তে 😉

This is the the code to change any array to hashmap . use a key String or Function type parameter in toHashMap('_id')
method
Convert array to hashmap
// ./utils/Array.hashmap.jsfunction isFunction(func) { return Object.prototype.toString.call(func) === '[object Function]';}Array.prototype.toHashMap = function (key) {
var _hashMap = {}, getKey = isFunction(key) ? key : function (_obj) { return _obj[key]; }; var _hashMap = {}, getKey = isFunction(key) ? key : function (_obj) { return _obj[key]; }; this.forEach(function (obj) { _hashMap[getKey(obj)] = obj._doc;});return _hashMap;};module.exports = Array;

Our previous style code

Our previous style response

New style Code

Hashmapped response

Thank You