How to convert array into object with out zeroth position

How to convert array into object with out zeroth position

Problem Description:

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"
}

Solution – 1

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

const [loanObj] = loanArray

console.log(loanObj)
Rate this post
We use cookies in order to give you the best possible experience on our website. By continuing to use this site, you agree to our use of cookies.
Accept
Reject