I have a dynamically built object and I need to extract specific fields (the dynamic ones) from it and convert them into an array.
In the following code snippet, my goal is to convert towers[X] into an array of objects.
{id: "", description: "Teste", towers[1]: true, towers[2]: true,
towers[3]: true, …}
description: "Test"
id: ""
towers[1]: true
towers[2]: true
towers[3]: true
towers[4]: ""
}
The desired outcome would look something like this:
{
id: "",
description: "Test",
towers[1]: true //Can remain here or be omitted as it won't be used
...
}
This should result in a new array structured like:
{
[id: 1, value: true],
[id: 2, value: true],
[id: 3, value: true],
[id: 4, value: ""]
}