-2

I need to extract the key value pairs from the order object and i want it to be combined to formData

Code

  const formData = {
      avatar: this.image,
      documents: this.order.documents,
      Object.entries(orders)
   };

Expected Output

avatar: 'http://images',
document: 'http://document',
Name: 'John Doe',
Food: 'Banana'

Object

orders: {
  'Name': 'John Doe',
  'Food': 'Banana'
}
Joseph
  • 7,042
  • 23
  • 83
  • 181

2 Answers2

0

Oh, you need the spread operator

const formData = {
      avatar: this.image,
      documents: this.order.documents,
      ...orders
   };
Keithers
  • 354
  • 6
  • 23
bill.gates
  • 14,145
  • 3
  • 19
  • 47
0

use the spead operator:

const formData = {
  avatar: this.image,
  documents: this.order.documents,
  ...orders
};
olkivan
  • 89
  • 1
  • 3