how to iterate an object in nodejs

1

I did this function:

const obj = [{id: 'a', time: 1}, {id: 'a', time: 2}, {id: 'b', time: 1}];

const objMapped = obj.reduce((acc, item) => {
  let { id, time } = item;
  acc[id] = acc[id] || [];
  acc[id].push(time);
  return acc;
}, {});

console.log(objMapped);

But I can not iterate since it's not a Array , it's actually a Objeto

    
asked by hubman 20.09.2016 в 16:24
source

1 answer

3

JavaScript Objects have a method keys () on which returns a Array with the enumerable properties of it:

Object.keys(obj).forEach(key => {
  let value = obj[key]
})
    
answered by 20.09.2016 / 16:32
source