Insert element inside array

I have a function

checkName(output) {

  output.filter((NewData) => {
    return this.props.elements.filter((OldData) => {
      if (NewData.key == OldData.key) {
        NewData.name = OldData.name,
          //there i need to add another element 
          // Need to add newData.number = OldData.number
      }
      return NewData
    })
  })
  
  return output
}

and I call this function like:

const named = this.checkName(product.rows)

Now I need to add to my product’s array that I passed to checkName the value "OldData.Number" to "newData.Number" that is not defined in product (so I need to create this field)

For example:

Product before the checkName function

product.rows = [NewData.name]

Product after the checkName function

product.rows = [NewData.name="value of OldData.name", NewData.number="value of OldData.number"]

How can I obtain this result?

19 thoughts on “Insert element inside array”

Leave a Comment