I have an object with the following structure:
data =
{
columns: array of objects,
rows: [
{
id: 1,
process: "A",
status: "ok"
},
{
id: 2,
process: "A",
status: "ko"
},
{
id: 3,
process: "B",
status: "ok"
},
...
]
}
I then want to create another object that has the same column
values, but in the rows
field I want to put only the objects that have process === "A"
.
I've come up with this so far, that I think it's fine:
const filteredData = {
"columns": data.columns,
"rows": selectedProcess !== '' ? data.rows.filter(r => r.process === selectedProcess) : []
}
My question is if there is another way to make this in a more clever way.