Hi maybe I'm block headed or just tired:
But i can't find an easy solution to update / manipulate an object array.
(without several loops)
I'm getting (via a Listener callback every second) status updates in the form:
status = {
uuid: "1065d90b-1a90",
status: "running",
data1: "xxx",
data2: "xxx", ...
}
status = {
uuid: "4075a90c-2b77",
status: "new",
data1: "xxx",
data2: "xxx", ...
}
It could be a new data set (with new uniq uuid) or an update for an existing data set (existing uuid)
I want to collect them in a table and need an array in the form:
[ {uuid: "1065d90b-1a90", status: "running", data1:"xxx", ...},
{uuid: "4075a90c-2b77", status: "new", data1: "xxx", ...}, {uuid: ...} ]
I have tried a hash list (better key:value) based in the uuid as index:
let allStatus[status.uuid] = status
This works and is easy and fast on updates, but this produce:
{ 1065d90b-1a90: {uuid: "1065d90b-1a90", status: "running", data1:"xxx", ...},
4075a90c-2b77: {uuid: "4075a90c-2b77", status: "new", data1: "xxx", ...},
xxxxxxxx-xxxx: {uuid: ...}
}
I can after that copy the complete list to the wanted array form. But I really like to avoid this since this will everytime (every sec) recreate the list, what is no good since it is used in a angular table for display.
How can I improve and direct update (create) the list/array?
.find(),.filter(), ...) then store the index of a "state" in an object with the uuid as the key:{ "1065d90b-1a90": 0, "4075a90c-2b77": 1 }list.push(update)or am I missing something?