0

I have two JSON arrays say,

A:

[ {"id": 123, "name": "AnyName1", "type": "AnyType"},
{"id": 231, "name": "AnyName2", "type": "AnyType"} ]

B:

[ {"id": 569, "thing": "AnyThing3"},
{"id": 891, "thing": "AnyThing4"} ]

I want to merge these two arrays (irrespective of ids) in a common JSON array:

C=A+B:

[ {"id": 123, "name": "AnyName1", "type": "AnyType"},
{"id": 231, "name": "AnyName2", "type": "AnyType"},
{"id": 569, "thing": "AnyThing3"},
{"id": 891, "thing": "AnyThing4"} ]

I want to achieve this without using a loop. Can someone help me with any shortcut way to do this in Typescript?

vahdet
  • 6,357
  • 9
  • 51
  • 106
  • actually, for an array use [ ], can you fix your code? And im pretty sure this is a duplicate. – Anouar Sep 28 '18 at 13:50

1 Answers1

0

You are looking for the concat method:

let C = A.concat(B);

(There may be a duplicate, but it would take me longer to find it than to write the above.)

Matt McCutchen
  • 28,856
  • 2
  • 68
  • 75