Any idea how can i access these 2 values inside the array?

There’s a great page in the docs (Working with messages : Node-RED) that will explain how to use the debug panel to find the right path/value for any data item.

Pay particular attention to the part about the buttons that appear under your mouse pointer when you over hover a debug message property in the sidebar.

BX00Cy7yHi

not sure what's wrong here. I get this error

If an object key can't be referenced by the dot notation, you can try square brackets
gate[0]["_"] and gate[1]["_"]

It looks as though you are working with badly formatted JSON data.
Where does this data come from & what happens to it in lines 1 - 47 of your function?

If you feed legData to a debug node as @smcgann99 hints, you can explore the object structure and use the Copy path button to obtain each element path in the appropriate format, dot or square brackets.

What do you get for the elements when you use the Copy Path feature pointed out in the previous post?

[Edit] Actually it is complaining that gate is not defined, assuming that the error is coming from the line you show. Put back the warn statement showing gate and add another after the next line.

@zaid NOTE: It's always better to copy actual text rather than screenshots, as it's much easier for people to help if they don't have to type everything out, also less chance of mistakes.

I have tried to recreate your problem in this flow and as you can see it works OK.

So it may be that what you are assigning to gate, doesn't always contain what you think.
Add back the first warn to show content of gate, then another to show after concatenation.

[{"id":"f5665d4b4f4387e7","type":"inject","z":"055c98606c931f5b","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"str","x":350,"y":1660,"wires":[["a36f0795db2a4416"]]},{"id":"a36f0795db2a4416","type":"function","z":"055c98606c931f5b","name":"function 3","func":"let gate = [\n    {\n        \"_\": \"23A\",\n        \"$\": {\n            \"wibble\": \"wobble\"\n        }\n    },\n    {\n        \"_\": \"23B\",\n        \"$\": {\n            \"wibble\": \"wobble\"\n        }\n    }\n]\n\nnode.warn(gate)\nnode.warn(gate[0]._ + \", \" + gate[1]._ );\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":520,"y":1660,"wires":[[]]}]

EDIT: Just looking again at your first post, I see that sometimes its an object and sometimes an array. In this case you will definitely get errors about missing properties !

It looks like you may be using the xml node to create that data from something... maybe try the fastxml node instead as it generally creates easier to work with objects with less arrays within.