How to create a new array by raising the id attribute in the object array

while learning js, I saw an article suggesting that arrays should be modeled, and now I have some doubts.

original array:

[{id:"111",title:"title1",body:"body1"},
{id:"222",title:"title2",body:"body2"}]

id


want to learn to use Object.assign or other methods, but no matter how to write it wrong, ask for advice

knows that writing like this can only copy the original array
Object.keys (org). Map (key = > Object.assign ({}, org.key])
but how to propose a layer?

Mar.12,2021

elegantly unexpectedly, simple and rude can use the following

const arr = [
  { id: '111', title: 'title1', body: 'body1' },
  { id: '222', title: 'title2', body: 'body2' }
]

const obj = {}

arr.forEach(item => {
  obj[item.id] = item
})

console.log(obj)

const arr = [
  { id: '111', title: 'title1', body: 'body1' },
  { id: '222', title: 'title2', body: 'body2' }
]

const obj=arr.reduce((sum,next)=>({...sum,[next.id]:next}),{})
console.log(obj)
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1be942d-31981.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1be942d-31981.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?