Joao Livio
Joao Livio

Reputation: 129

Join 2 items from an Array and add it as Item in the same array

I have this Array of items. The problem is I need to join the CertificateNumber and Ordinal from all the items and add a new value for each.

So I can have CertificateJoin: AAAAA00

AAAAA is the CertificateNumber and 00 is the Ordinal

How can I do this?

enter image description here

Upvotes: 0

Views: 28

Answers (1)

Balastrong
Balastrong

Reputation: 4464

You can just cycle through your array and put your merged value in a new property, like so:

var items = [{
    fieldA: 1,
    fieldB: "A"
  },
  {
    fieldA: 2,
    fieldB: "B"
  }
]

items.forEach(item => item["join"] = item.fieldA + item.fieldB);

console.log(items);

Upvotes: 1

Related Questions