javascript array immutable code example

Example: how to iimutable aray javascript

const originalValue = [
  { id: 'a11-a', createdAt: "2021-05-12T01:35:59.000Z" },
  { id: 'a11-b', createdAt: "2021-05-12T01:35:48.000Z" },
  { id: 'a11-c', createdAt: "2021-05-12T00:28:32.000Z" },
  { id: 'b11-a', createdAt: "2021-05-12T00:27:43.000Z" },
  { id: 'b11-b', createdAt: "2021-05-12T00:26:36.000Z" },
  { id: 'b11-c', createdAt: "2021-05-12T00:24:01.000Z" }
]

const modifValue = []

originalValue.forEach(val => {
  const arrObject = Object.create(val)
  arrObject.id = arrObject.id.replace(/-\w+/, '')
  modifValue.push(arrObject)
})

console.log(originalValue)
console.log(modifValue)