-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
  • 5,548
  • 14
  • 57
  • 125

2 Answers2

0

Oh, you need the spread operator

const formData = {
      avatar: this.image,
      documents: this.order.documents,
      ...orders
   };
Keithers
  • 344
  • 5
  • 23
bill.gates
  • 12,086
  • 2
  • 10
  • 33
0

use the spead operator:

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