I am currently working with an object that contains nested objects:
{
"0": {
"boardingGate": "exit_0",
"departureTerminal": "1",
"terminalArea": 0,
"arrivalGate": "enter_0",
"arrivalTerminal": "2",
"terminalArea": 0
},
"1": {
"boardingGate": "exit_1",
"departureTerminal": "1",
"terminalArea": 0,
"arrivalGate": "enter_1",
"arrivalTerminal": "2",
"terminalArea": 0
},
"2": {
"boardingGate": "exit_0",
"departureTerminal": "1",
"terminalArea": 0,
"arrivalGate": "enter_0",
"arrivalTerminal": "3",
"terminalArea": 0
},
"3": {
"boardingGate": "exit_1",
"departureTerminal": "2",
"terminalArea": 0,
"arrivalGate": "enter_1",
"arrivalTerminal": "3",
"terminalArea": 0
}
}
My task is to update all "boardingGate" values to "exit_0" and all "arrivalGate" values to "enter_0". After this transformation, any objects with identical structures should be removed. The desired output after these operations is as follows:
{
"0": {
"boardingGate": "exit_0",
"departureTerminal": "1",
"terminalArea": 0,
"arrivalGate": "enter_0",
"arrivalTerminal": "2",
"terminalArea": 0
},
"1": {
"boardingGate": "exit_0",
"departureTerminal": "1",
"terminalArea": 0,
"arrivalGate": "enter_0",
"arrivalTerminal": "3",
"terminalArea": 0
},
"2": {
"boardingGate": "exit_0",
"departureTerminal": "2",
"terminalArea": 0,
"arrivalGate": "enter_0",
"arrivalTerminal": "3",
"terminalArea": 0
}
}
I have attempted a solution using forEach by accessing Object.values(data), but I haven't been able to achieve the desired outcome. I'm unsure if there's a simpler approach to solving this problem.
const tickets = Object.values(data);
tickets.forEach((next, index, ticket) => {
const boardingGateKeys: any = Object.keys(next.boardingGate);
const boardingGateValues: any = Object.values(next.boardingGate);
boardingGateKeys.forEach((gate, gateIndex) => {
const arrivalGateKeys: any = Object.keys(gate.outputs);
const arrivalGateValues: any = Object.values(gate.outputs);
arrivalGateValues.forEach((output, outputIndex) => {
});
}
});
});
Your assistance with this problem would be greatly appreciated. Thank you in advance.