0
const obj = {
  0: {
    name: 'item1',
    slug: 'slug1',
    price: 64,
    featured_image: null,
    onSale: undefined,
    // ...
  },
  1: {
   name: 'item2',
    slug: 'slug2',
    price: 64,
    featured_image: null,
    onSale: undefined,
    // ...
  },
  2: {
      name: 'item3',
    slug: 'slug3',
    price: 64,
    featured_image: null,
    onSale: undefined,
    // ...
  }
};

Result I expect:

const obj = [ { name: 'item1', slug: 'slug1', price: 64, featured_image: null, onSale: undefined, }, { name: 'item2', slug: 'slug2', price: 64, featured_image: null, onSale: undefined, }, { name: 'item3', slug: 'slug3', price: 64, featured_image: null, onSale: undefined, } ]

I cannot get ride of the index of each element of the array in order to map the function properly, any help would be appreaciate it.

i tried with Object.values but still

murdock_
  • 3
  • 2

1 Answers1

0

You have an object of objects with each key an index. It sounds as if you want an array of objects relating to the values of the incoming object.

Array.from(Object.values(obj))

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/values

Arjax
  • 25
  • 5