Array to Hashmap in Express application

Samayun Miah Chowdhury
2 min readJun 19, 2021

--

এই আমি সামায়ুন,
এই আমার ফ্রেমওয়ার্ক ( https://github.com/samayun/express-mvc-rest-boilerplate )
এবার পার্টি হবে যে 😉

ব্যক্তিগত কারণে এরে ডাটা স্ট্রাকচারে কে ডিভোর্স দিয়ে হ্যাশম্যাপ ব্যবহার করতে যাচ্ছি ।
আপনিও গাড়িসহ আমার সাথে আত্মগোপনে যেতে চলে আসুন আমার রিপোজিটরি তে 😉

Hashmap in Javascript
Image : Hashmap in JavaScript

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

Previous output for our array based response

New style Code

Hashmapped response

Current response version converted into hashmap

Thank You

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Samayun Miah Chowdhury
Samayun Miah Chowdhury

Written by Samayun Miah Chowdhury

Fan of JavaScript & Python lover Feels good to introduced as a realtime web application developer sunglasses PWA is my crushwink I do 2 times teeth brush

No responses yet

Write a response