SHARE
TWEET

Untitled

a guest Oct 22nd, 2019 86 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let test = {"id1":{"age":30,"name":"dori"}}
  2. let result = {"id1/name":"dori","id1/age":30}
  3. function pathAtributes(object, _key = '', paths = {}) {
  4.     if (typeof object !== 'object') return [_key, object]
  5.     let path = ''
  6.     let keys = Object.getOwnPropertyNames(object)
  7.     for (const key in keys) {
  8.         path = _key.length ? _key + '/' + keys[key] : keys[key]
  9.         let values = getTranslateToPath(object[keys[key]], path, paths)
  10.         if (values[0])
  11.             paths[values[0]] = values[1]
  12.     }
  13.     return paths
  14. }
  15. console.log(pathAtributes(test))
  16. console.log(result)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top