0

I am looping over list of objects but when calling a async function I get array of objects with numbers and now i cannot map the arrays.

    {
  '0': {
    id: '22be325d3564d713',
    name: 'dasdasdas',
    affiliateIds: 2,
    platformIds: 2,
    campaignIds: [],
    deviceOses: [],
    deviceTypes: [],
    countryCodes: [],
    entryType: 'RED',
    model: 'REVENUE_RATIO',
    value: 0.01,
    active: 1,
    createdAt: 2020-06-11T06:00:53.000Z,
    updatedAt: 2020-06-11T06:00:53.000Z
  },
  '1': {
    id: '2891e303645099fd',
    name: '',
    affiliateIds: [],
    platformIds: [],
    campaignIds: [],
    deviceOses: [],
    deviceTypes: [],
    countryCodes: [],
    entryType: 'CNV',
    model: 'REVENUE_RATIO',
    value: 0.7,
    active: 1,
    createdAt: 2018-01-09T11:12:29.000Z,
    updatedAt: 2018-01-09T11:12:29.000Z
  },

i am trying to get the ids using

Object.map(a => a.id);

but because of the numbers i cannot get the ids

1 Answers1

3

You can use Object.values() if you are not interested in the numeric property names

const res = Object.values(data).map(({id}) => id)

console.log(res)
<script>
const data={0:{id:"22be325d3564d713",name:"dasdasdas",affiliateIds:2,platformIds:2,campaignIds:[],deviceOses:[],deviceTypes:[],countryCodes:[],entryType:"RED",model:"REVENUE_RATIO",value:.01,active:1,createdAt:"2020 - 06 - 11 T06: 00: 53.000 Z",updatedAt:"2020 - 06 - 11 T06: 00: 53.000 Z"},1:{id:"2891e303645099fd",name:"",affiliateIds:[],platformIds:[],campaignIds:[],deviceOses:[],deviceTypes:[],countryCodes:[],entryType:"CNV",model:"REVENUE_RATIO",value:.7,active:1,createdAt:"2018 - 01 - 09 T11: 12: 29.000 Z",updatedAt:"2018 - 01 - 09 T11: 12: 29.000 Z"}};
</script>
charlietfl
  • 170,828
  • 13
  • 121
  • 150