-1

I'm trying to convert an array into an object

"loanArray" : [
   {
    "recordID" : "LKOCH123",
    "date" : "20221206",
    "productId" : "21023"
   }
]

I've converted this into an Object using Object.assign like below:

let loanObj= Object.assign({}, loanArray)
"loanObj" : {
   "0": {
    "recordID" : "LKOCH123",
    "date" : "20221206",
    "productId" : "21023"
   }
}

However, I want to remove that "0" position in my object, and the expected is below: please help to achieve this structure.

"loanObj" : {
    "recordID" : "LKOCH123",
    "date" : "20221206",
    "productId" : "21023"
}
providerZ
  • 315
  • 11
Mar1009
  • 721
  • 1
  • 11
  • 27

1 Answers1

2

const loanArray = [{recordID: 'LKOCH123', date: '20221206', productId: '21023'}]

const [loanObj] = loanArray

console.log(loanObj)
Andrew Parks
  • 6,358
  • 2
  • 12
  • 27