This is how my dataset looks like:
const data = {
"VS_factor": [
"FA1_n",
"FA1_y",
"FA2_n"
],
"coord.Dim.1": [
-0.232849099744328,
0.875136458459595,
-0.0810629616429348,
],
"coord.Dim.2": [
0.0223397885030092,
-0.0839615159119212,
-0.334981738274959,
],
"cluster": [
0,
5,
0,
]
}
I want to filter the object and every array inside based the value of the last variable. In this example I only want to keep the values where cluster" === 5.
const desired = {
"VS_factor": [
"FA1_y",
],
"coord.Dim.1": [
0.875136458459595,
],
"coord.Dim.2": [
-0.0839615159119212,
],
"cluster": [
5,
]
}
I have trouble with this since I can not use .filter on an Object. Does anyone know a solution how to archieve my desired result?
filteron them.findIndexto get the desired index, then just filter all the arrays on the index found. Of course, there are many caveats for such approach, like the fact that you might have arrays of different length and, so, in such cases, the result would be wrong.