Accessing elements from 2 JSON arrays and combining them together in a specific order in Javascript : So I have console.log output to show what I want. 

Array [ "srs-rt3" ]

Array [  ]

Array [ "srs-rt3" ]

Array [ "srs-rt3", "atla-cr5" ]

Array [ "srs-rt3:ge-0/1/0 -- atla-cr5:10/1/3" ]

Array [ "srs-rt3", "atla-cr5", "srs-rt3:ge-0/1/0 -- atla-cr5:10/1/3" ]

Array [ "srs-rt3", "atla-cr5", "ornl-cr5" ]

Array [ "srs-rt3:ge-0/1/0 -- atla-cr5:10/1/3", "atla-cr5:3/1/1 -- ornl-cr5:6/1/1" ]


The output is logged as and when I select each node in a network on the web UI.
The first array is for nodes selected and second is for links(It is empty because only one node is selected and there is no second node to link it).

 When a second node is selected a link between 2 ports gets updated in the fourth array and this goes on as and when I keep selecting nodes.[Web UI][2]

**What I want is an array with something like this**

Array [srs-rt3, srs-rt3:ge-0/1/0,atla-cr5:10/1/3,atla-cr5, atla-cr5:3/1/1, ornl-cr5:6/1/1, ornl-cr5   ]

**So the array should be ideally** 

{deviceA, firstPort, secondPort, deviceB, firstPort, secondPort, deviceC}


  [1]: https://i.stack.imgur.com/bRFLP.jpg
  [2]: https://i.stack.imgur.com/vhu2A.png
 
Any inputs would be greatly appreciated
