0

I have object in redux store

  `{455:{id:'455',name'test'},456:{id:'456',name:'test2},457:{id:'457',name'test3'},...}`. 

At now I iterate values with method Object.keys. Have any more elegant method for this case? Many Thanks.

Ved Rauniyar
  • 1,539
  • 14
  • 21
  • 1
    Possible duplicate of [map function for objects (instead of arrays)](http://stackoverflow.com/questions/14810506/map-function-for-objects-instead-of-arrays) – Joe Clay May 22 '17 at 10:30

1 Answers1

0

In stead of using Object.keys to map over the object, you can use Object.values() that returns an array of values and then map over them like

var obj = {
  '455': {
    id: '455',
    name:'test'
  },
  '456': {
    id: '456',
    name: 'test2'
  },
  '457': {
    id: '457',
    name:'test3'
  }
}
Object.values(obj).map((val) => console.log(val))
Shubham Khatri
  • 270,417
  • 55
  • 406
  • 400