0

I am unable to loop through the multidimensional map, I have a sample map below, here known values are its key. i.e 'one', 'two'.. Now how can I find out the inner values of it. I would like to get a,b from one and c,d from two

{
  one: {
    a: {
      id: '6',
      name: 'abc',
      age: '30',
      place: 'xyz'
    },
    b: {
      id: '7',
      name: 'def',
      age: '31',
      place: 'xyx'
    },
  },
  two: {
    c: {
      id: '8',
      name: 'ghi',
      age: '32',
      place: 'xxz'
    },
    d: {
      id: '9',
      name: 'ghi',
      age: '33',
      place: 'yyx'
    }
  }
}

It would be really helpful if I get any solution for this..Thanks in advance

OGURA Daiki
  • 177
  • 5
Karthikeya Vaidya
  • 111
  • 1
  • 3
  • 7
  • Possible duplicate of [How to find keys of a hash?](http://stackoverflow.com/questions/18912/how-to-find-keys-of-a-hash) – Gavriel Jan 19 '16 at 10:11
  • you can use them like json [http://stackoverflow.com/questions/1078118/how-do-i-iterate-over-a-json-structure](example) – kayosoufiane Jan 19 '16 at 10:16

1 Answers1

2

You can do something like this:

Object.keys(obj).map(function (key) {
  return Object.keys(obj[key])
})

Object.keys return the keys of the object, and you can map those keys using the map method. The key name is passed to the map and it return the keys of each object stored on each keys. It's not so clear why you need that as you kind of loose the parent and children nodes while doing this.

Loïc Faure-Lacroix
  • 13,220
  • 6
  • 67
  • 99
  • Object.entries() returns [key, value] pairs: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries – jaggedsoft Apr 20 '20 at 09:08