Home > Software design >  How to create an array of numbers from my object?
How to create an array of numbers from my object?

Time:12-09

I have an object with different datas, and I need to create a new array with only ID's of this object. With simple this.object.push(data.id) I get an array like this but I need to get somenthing like this

CodePudding user response:

You should use map function from an array like below:

   let object = this.data.map(r => r.id)

this will return your array of ids only. output: ['1', '2']

CodePudding user response:

You can use either

let result = this.obj.map(r => r.id)

or

let result = this.obj.map(({id}) => id)
  • Related