1

Hice esta función:

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);

Pero no puedo iterarlo ya que no es un Array, en realidad es un Objeto

1 respuesta 1

3

Los Objetos de JavaScript tienen un método keys() el cual devuelve un Array con las propiedades enumerables del mismo:

Object.keys(obj).forEach(key => {
  let value = obj[key]
})

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.