I have an array of objects like this,
value = [
{"f1_x":1, "f1_y":3, "f2_x": 5},
{"f1_x":2, "f2_y":4, "f2_x": 6}
]
Now, I only want to keep key/value pairs where key ends with _x
. So, the above would look like this,
value = [
{"f1_x":1, "f2_x": 5},
{"f1_x":2, "f2_x": 6}
]
I used the following, but is there any more elegant way of doing the same?
var x = value.map(e => {
r = {}
for (const f in e)
if (f.toLowerCase().endsWith("_x"))
r[f] = e[f]
return r
})