informaticage

js map to obj

Jan 25th, 2021
433
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. accessObjectFromFlatMapFieldName(object, key, toAccess, avoids = []) {
  2.     let currentLevel = object;
  3.     key.split('.').forEach((k,i) => {
  4.       console.log(k, i);
  5.       if(k === toAccess) {
  6.         console.log('Found level', currentLevel);
  7.         return currentLevel;
  8.       }
  9.  
  10.       if(!avoids.includes(k)) {
  11.         currentLevel = currentLevel[k];
  12.       }
  13.     });
  14.     return currentLevel;
  15.   }
RAW Paste Data