1

Is there anyway to convert this like the example below?

Convert this:

[
  RowDataPacket { title: 'Code' },
  RowDataPacket { title: 'Pizza' }
]

Into this:

['Code', 'Pizza']
Vera Perrone
  • 369
  • 1
  • 15

2 Answers2

4

I've provided you two possible solutions, in case if it's just an array of objects or an array of nested objects.

var arr = [{RowDataPacket: { title: 'Code' }}, {RowDataPacket: { title: 'Pizza' }}],
    res = arr.map(v => v.RowDataPacket.title);
    console.log(res);

var arr = [{ title: 'Code' }, { title: 'Pizza' }],
    res = arr.map(v => v.title);
    console.log(res);
kind user
  • 40,029
  • 7
  • 67
  • 77
-1

Create a new array

var newArr = [];

And then push each item into the array

result.forEach(function(obj){
   newArr.push(obj.title);
}