Why Am I not getting add a new key and value to an existence object?

I Have the follow object which iterating it I can add a new key and value, but when I have to make a database search and take each result and add as a new key + value does not work, the Eslint point a Assignment to property of function parameter 'object'.eslintno-param-reassign, bellow is the example without make a database search.

const obj = {
  Cod: 43453,
  Informations: [
    {
      codPay: 802112,
      value: 80
    },
    {
      codPay: 802113,
      value: 80
    },
    {
      codPay: 802114,
      value: 80
    },
    {
      codPay: 802115,
      value: 80
    },
    {
      codPay: 802116,
      value: 80
    },
    {
      codPay: 802117,
      value: 80
    },
    {
      codPay: 802118,
      value: 80
    },
    {
      codPay: 802119,
      value: 80
    }
  ],
  status: 'OK'
}



obj["Informations"].forEach((f,index) => {
    f.more_info = index
})

console.log(obj)

By making database search:

obj["Informations"].forEach(asyn(f) => {
    const result = db.any("Select info From table where cod $1",f.codPay")
    f.more_info = result[0].info
})

by openning this db.any the values is coming correct but I cannot add new key, where Am I missing?

9 thoughts on “Why Am I not getting add a new key and value to an existence object?”

Leave a Comment